package com.git.smp.controller;

import java.io.IOException;
import java.io.OutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.annotation.Resources;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.activiti.engine.FormService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.IdentityLink;
import org.activiti.engine.task.Task;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFHyperlink;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.json.GsonJsonParser;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.git.smp.Exception.SmpException;
import com.git.smp.cache.DataDictionaryCache;
import com.git.smp.cache.EsbEnvironmentCache;
import com.git.smp.cache.SmpSystemCache;
import com.git.smp.core.PageRequest;
import com.git.smp.core.ResponseMessage;
import com.git.smp.dao.ApplyAppendixMapper;
import com.git.smp.dao.ApplyEnvironmentMapper;
import com.git.smp.dao.ApplyFieldMapper;
import com.git.smp.dao.ApplyServerMapper;
import com.git.smp.dao.ApplySystemCallMapper;
import com.git.smp.dao.ApplySystemMapper;
import com.git.smp.dao.EsbEnvironmentMapper;
import com.git.smp.dao.RequireApplyMapper;
import com.git.smp.dao.RequirementBatchMapper;
import com.git.smp.dao.RequirementBatchTiemMapper;
import com.git.smp.dao.SmpEnvironmentMapper;
import com.git.smp.dao.SmpFieldMapper;
import com.git.smp.dao.SmpServiceHisMapper;
import com.git.smp.dao.SmpUserRoleMapper;
import com.git.smp.dao.SystemCallProxyPathMapper;
import com.git.smp.dao.smpFieldHisMapper;
import com.git.smp.dao.SmpServiceMapper;
import com.git.smp.dao.SmpSystemCallMapper;
import com.git.smp.dao.SmpSystemMapper;
import com.git.smp.entity.ApplyAppendix;
import com.git.smp.entity.ApplyAppendixKey;
import com.git.smp.entity.ApplyEnvironment;
import com.git.smp.entity.ApplyField;
import com.git.smp.entity.ApplyServer;
import com.git.smp.entity.ApplyServerExtend;
import com.git.smp.entity.ApplyServerKey;
import com.git.smp.entity.ApplySystem;
import com.git.smp.entity.ApplySystemCall;
import com.git.smp.entity.ApplySystemCallExtend;
import com.git.smp.entity.CallListInfo;
import com.git.smp.entity.EsbEnvironment;
import com.git.smp.entity.RequireApply;
import com.git.smp.entity.RequireApplyDetail;
import com.git.smp.entity.RequireApplyExtend;
import com.git.smp.entity.RequirementBatch;
import com.git.smp.entity.RequirementBatchKey;
import com.git.smp.entity.RequirementBatchTiem;
import com.git.smp.entity.RequirementBatchTiemExtend;
import com.git.smp.entity.SmpEnvironment;
import com.git.smp.entity.SmpField;
import com.git.smp.entity.SmpService;
import com.git.smp.entity.SmpServiceExtend;
import com.git.smp.entity.SmpServiceHis;
import com.git.smp.entity.SmpServiceKey;
import com.git.smp.entity.SmpSystem;
import com.git.smp.entity.SmpSystemCall;
import com.git.smp.entity.SmpSystemCallExtend;
import com.git.smp.entity.SystemCallProxyPath;
import com.git.smp.entity.smpFieldHis;
import com.git.smp.utils.Constants;
import com.git.smp.utils.ObjectUtil;
import com.git.smp.utils.StringUtil;
import com.git.smp.websocket.IndexServer;
import com.git.smp.websocket.TaskServer;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@RestController
@RequestMapping("/demand")
public class RequireApplyController {

	Logger logger = LoggerFactory.getLogger(RequireApplyController.class);

	@Autowired
	RequireApplyMapper requireApplyMapper;

	@Autowired
	ApplySystemMapper applySystemMapper;

	@Autowired
	ApplyServerMapper applyServerMapper;

	@Autowired
	ApplyFieldMapper applyFieldMapper;

	@Autowired
	ApplySystemCallMapper applySystemCallMapper;

	@Autowired
	SmpServiceHisMapper smpServiceHisMapper;

	@Autowired
	smpFieldHisMapper fieldHisMapper;

	@Autowired
	SmpSystemMapper smpSystemMapper;

	@Resource
	RuntimeService runtimeService;

	@Resource
	TaskService taskService;

	@Resource
	HistoryService historyService;

	@Resource
	RepositoryService repositoryService;

	@Autowired
	ProcessEngineConfiguration engineConfiguration;

	@Autowired
	FormService formService;

	@Autowired
	private HttpServletRequest request;

	@Autowired
	SmpServiceMapper smpServiceMapper;

	@Autowired
	private HttpServletResponse response;

	@Autowired
	ApplyAppendixMapper applyAppendixMapper;

	@Autowired
	SmpSystemCallMapper smpSystemCallMapper;

	@Autowired
	SmpSystemMapper smpServiceManagementSystemMapper;

	@Autowired
	SmpFieldMapper smpFieldMapper;

	@Autowired
	RequirementBatchMapper requirementBatchMapper;

	@Autowired
	RequirementBatchTiemMapper requirementBatchTiemMapper;

	@Autowired
	SmpEnvironmentMapper smpEnvironmentMapper;

	@Autowired
	ApplyEnvironmentMapper applyEnvironmentMapper;

	@Autowired
	SmpUserRoleMapper smpUserRoleMapper;

	@Autowired
	SystemCallProxyPathMapper systemCallProxyPathMapper;

	@Autowired
	SmpSystemCache systemCache;

	@Autowired
	TaskServer taskServer;
	
	
	

	@Value("${adminRoleId}")
	private String adminRoleId;

	@Value("${developRoleId}")
	private String developRoleId;

	@Value("${testRoleId}")
	private String testRoleId;
	
	
	@Value("${templateversion}")
	private String templateversion;
	

	// 分页查询数据
	@RequestMapping("/getDemandByPage")
	public ResponseMessage<PageInfo<RequireApply>> getDemandByPage(
			@RequestBody PageRequest<RequireApplyExtend> pageRequest) {
		ResponseMessage<PageInfo<RequireApply>> responseMessage = new ResponseMessage<PageInfo<RequireApply>>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("查询成功！");

		RequireApplyExtend requireApplyExtend = pageRequest.getBody();

		PageHelper.startPage(pageRequest.getPageNum(), pageRequest.getPageSize());
		List<RequireApply> listRequireApply = requireApplyMapper.getDemandByPage(requireApplyExtend);
		if (listRequireApply == null) {
			responseMessage.setCode("0001");
			responseMessage.setMessage("查询菜单信息失败！");
		}
		PageInfo<RequireApply> pageInfo = new PageInfo<RequireApply>(listRequireApply, pageRequest.getPageSize());
		responseMessage.setExtend(pageInfo);
		logger.info(responseMessage.getMessage());
		return responseMessage;
	}

	/**
	 * 
	 * @param Id
	 * @return
	 */
	@RequestMapping("/getDemandDetails")
	public ResponseMessage<RequireApplyDetail> getDemandDetails(
			@RequestParam(value = "id", defaultValue = "") String id) {
		ResponseMessage<RequireApplyDetail> responseMessage = new ResponseMessage<RequireApplyDetail>();

		RequireApply requireApply = requireApplyMapper.selectByPrimaryKey(id);

		List<ApplySystem> applySystemList = applySystemMapper.selectByApplyId(id);

		List<ApplyServerExtend> applyServerList = applyServerMapper.selectByApplyId(id);

		RequireApplyDetail requireApplyDetail = new RequireApplyDetail();
		requireApplyDetail.setRequireApply(requireApply);
		requireApplyDetail.setApplySystemList(applySystemList);
//		requireApplyDetail.setApplyServerList(applyServerList);

		responseMessage.setExtend(requireApplyDetail);
		logger.info(responseMessage.getMessage());
		return responseMessage;
	}

	/**
	 * 需求日历日视图
	 * 
	 * @param pageRequest
	 * @return
	 */
	@RequestMapping("/getDemandCalendarDay")
	public ResponseMessage<PageInfo<RequirementBatchTiemExtend>> getDemandCalendarDay(
			@RequestBody PageRequest<RequirementBatchTiem> pageRequest) {
		ResponseMessage<PageInfo<RequirementBatchTiemExtend>> responseMessage = new ResponseMessage<PageInfo<RequirementBatchTiemExtend>>();

		responseMessage.setCode("0000");
		responseMessage.setMessage("查询成功！");

		RequirementBatchTiem requirementBatchTiem = pageRequest.getBody();

		PageHelper.startPage(pageRequest.getPageNum(), pageRequest.getPageSize());

		List<RequirementBatchTiemExtend> batchList = requirementBatchTiemMapper
				.getDemandCalendarDay(requirementBatchTiem);

		if (batchList == null) {
			responseMessage.setCode("0001");
			responseMessage.setMessage("查询菜单信息失败！");
		}
		PageInfo<RequirementBatchTiemExtend> pageInfo = new PageInfo<RequirementBatchTiemExtend>(batchList,
				pageRequest.getPageSize());

		responseMessage.setExtend(pageInfo);
		logger.info(responseMessage.getMessage());
		return responseMessage;
	}

	/**
	 * 需求日历月视图
	 * 
	 * @param requirementBatchTiem
	 * @return
	 */
	@RequestMapping("/getDemandCalendar")
	public ResponseMessage<List<RequirementBatchTiemExtend>> getDemandCalendar(
			@RequestBody RequirementBatchTiem requirementBatchTiem) {
		ResponseMessage<List<RequirementBatchTiemExtend>> responseMessage = new ResponseMessage<List<RequirementBatchTiemExtend>>();

		RequirementBatchTiemExtend requirementBatchTiemExtend = new RequirementBatchTiemExtend();
		requirementBatchTiemExtend.setStatus(requirementBatchTiem.getStatus());

		// 根据传进的时间进行月初月末赋值,没有值算当月的
		Date date = new Date();
		if (requirementBatchTiem.getUpdateTime() != null
				&& !"".equals(requirementBatchTiem.getUpdateTime().toString())) {
			date = requirementBatchTiem.getUpdateTime();
		}

		Calendar cale = Calendar.getInstance();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		cale.setTime(date);

		cale.set(Calendar.DAY_OF_MONTH, 1);
		cale.set(Calendar.HOUR, 0);
		cale.set(Calendar.MINUTE, 0);
		cale.set(Calendar.SECOND, 0);

		String st = formatter.format(cale.getTime());

		Date startTime;
		try {
			startTime = formatter.parse(st);
			requirementBatchTiemExtend.setStartTime(startTime);
		} catch (ParseException e) {
			e.printStackTrace();
		}

		cale.set(Calendar.DAY_OF_MONTH, cale.getActualMaximum(Calendar.DAY_OF_MONTH));
		cale.set(Calendar.HOUR, 23);
		cale.set(Calendar.MINUTE, 59);
		cale.set(Calendar.SECOND, 59);

		st = formatter.format(cale.getTime());

		Date endTime;
		try {
			endTime = formatter.parse(st);
			requirementBatchTiemExtend.setEndTime(endTime);
		} catch (ParseException e) {
			e.printStackTrace();
		}

		List<RequirementBatchTiemExtend> batchList = requirementBatchTiemMapper
				.getDemandCalendar(requirementBatchTiemExtend);

		responseMessage.setExtend(batchList);
		logger.info(responseMessage.getMessage());
		return responseMessage;
	}

	/**
	 * 工单申请提交
	 * 
	 * @param requireApplyDetail
	 * @return
	 */
	@Transactional
	@RequestMapping("/addAll")
	public ResponseMessage<String> addAll(@RequestBody RequireApplyDetail requireApplyDetail) {
		ResponseMessage<String> response = new ResponseMessage<String>();
		response.setCode("0000");
		response.setMessage("提交成功");

		Date applyDate = new Date();
		String applyUser = request.getHeader("userName");

		int id = requireApplyMapper.getId();
		String sid = null;

		RequireApply requireApply = requireApplyDetail.getRequireApply();

		String applyStatus = requireApply.getStatus();
		
		//需求校验
		
		RequirementBatchKey requirementBatchKeyPre = new RequirementBatchKey();
		requirementBatchKeyPre.setBatchNum(requireApply.getBatchNum());
		requirementBatchKeyPre.setQmsNo(requireApply.getQmsNo());
		
		RequirementBatch requirementBatchpre = requirementBatchMapper.selectByPrimaryKey(requirementBatchKeyPre);
		if(requirementBatchpre!=null && "04".equals(requirementBatchpre.getStatus())) {
			response.setCode("0001");
			response.setMessage("当前批次已上线");
			return response;
		}
		

		// 校验提交环境维护工单的信息
		for (ApplyEnvironment applyEnvironment : requireApplyDetail.getApplyEnvironmentList()) {
			ResponseMessage<?> checkEnvirInfo = checkEnvirInfo(applyEnvironment);
			if ("0001".equals(checkEnvirInfo.getCode())) {
				response.setCode("0001");
				response.setMessage("环境维护校验不通过");
				return response;
			}
		}

		// 校验服务注册
		for (ApplyServerExtend applyServerExtend2 : requireApplyDetail.getApplyServerList()) {

			// 对ApplyServer进行校验
			// 查询ApplyServer是否有未完成流程
			ApplyServerExtend applyServer = new ApplyServerExtend();
			applyServer.setTransCode(applyServerExtend2.getTransCode());
			applyServer.setSystemNo(applyServerExtend2.getSystemNo());
			applyServer.setRequireType(applyServerExtend2.getRequireType());
			if (requireApply.getId() != null && !"".equals(requireApply.getId())) {
				applyServer.setApplyId(requireApply.getId());
			}

			applyServer.setQmsNo(requireApply.getQmsNo());
			applyServer.setBatchNum(requireApply.getBatchNum());

			// 调用检验方法
			ResponseMessage<?> applyServerCheck = getServerCheck(applyServer);
			if ("0001".equals(applyServerCheck.getCode())) {
				response.setCode("0001");
				response.setMessage(applyServerCheck.getMessage());
				return response;
			}

		}

		// 校验服务调用
		for (ApplySystemCall applySystemCall2 : requireApplyDetail.getApplySystemCallList()) {

			if (requireApply.getId() != null && !"".equals(requireApply.getId())) {
				applySystemCall2.setId(requireApply.getId());
			}
			// 调用检验方法
			ResponseMessage<?> applySystemCallCheck = getSystemCallCheck(applySystemCall2,
					requireApplyDetail.getRequireApply().getQmsNo());
			if ("0001".equals(applySystemCallCheck.getCode())) {
				response.setCode("0001");
				response.setMessage(applySystemCallCheck.getMessage());
				return response;
			}

		}

		// 系统维护校验
		for (ApplySystem applySystem2 : requireApplyDetail.getApplySystemList()) {

			if (requireApply.getId() != null && !"".equals(requireApply.getId())) {
				applySystem2.setApplyId(requireApply.getId());
			}
			// 调用检验方法
			ResponseMessage<?> applySystemCheck = getSystemCheck(applySystem2);
			if ("0001".equals(applySystemCheck.getCode())) {
				response.setCode("0001");
				response.setMessage(applySystemCheck.getMessage());
				return response;
			}
		}

		// 状态：0 已提交
		requireApply.setStatus("0");

		// 提交时如果是之前没有保存过的则插入新数据
		if (requireApply.getId() == null || "".equals(requireApply.getId())) {

			String preFix = "";

			switch (requireApply.getApplyType()) {
			case Constants.APPLY_TYPE_01:
				preFix = Constants.APPLY_PREFIX_01;
				break;
			case Constants.APPLY_TYPE_02:
				preFix = Constants.APPLY_PREFIX_02;
				break;
			case Constants.APPLY_TYPE_03:
				preFix = Constants.APPLY_PREFIX_03;
				break;
			case Constants.APPLY_TYPE_04:
				preFix = Constants.APPLY_PREFIX_04;
				break;
			default:
				preFix = Constants.APPLY_PREFIX_01;
				break;
			}

			sid = preFix + new SimpleDateFormat("yyyyMMdd").format(new Date()) + String.format("%04d", id);
			requireApply.setApplyDate(applyDate);
			requireApply.setApplyUser(applyUser);

			requireApply.setId(sid);

			int a = requireApplyMapper.insert(requireApply);

			Map param = new HashMap<>();
			param.put("applyUser", applyUser);
			param.put("qmsNo", requireApply.getQmsNo());
			param.put("qmsName", requireApply.getQmsName());
			param.put("sid", sid);
			param.put("applyType", requireApply.getApplyType());

			ProcessInstance instance = null;
//    		if(Constants.APPLY_TYPE_02.equals(requireApply.getApplyType())) {
//    			//查询服务方系统负责人
//    			String regSysNo = requireApply.getRegSysNo();
//    			
//    			SmpSystem smpSystem = smpSystemMapper.selectByPrimaryKey(regSysNo);
//    			param.put("serverSystemUser", smpSystem.getSystemResponsibleMan());
//    			
//				/*
//				 * instance = runtimeService.startProcessInstanceByKey("systemCallProcess",
//				 * param);
//				 */
//        		 instance = runtimeService.startProcessInstanceByKey("demandProcess", param);
//
//    		}else if(Constants.APPLY_TYPE_04.equals(requireApply.getApplyType())) {

			/*
			 * if (Constants.APPLY_TYPE_04.equals(requireApply.getApplyType())) {
			 * 
			 * //查询服务方系统负责人 String regSysNo = requireApply.getRegSysNo();
			 * 
			 * SmpSystem smpSystem = smpSystemMapper.selectByPrimaryKey(regSysNo);
			 * param.put("serverSystemUser", smpSystem.getSystemResponsibleMan());
			 * 
			 *
			 * 
			 * // 查询测试管理员 List<String> userList =
			 * smpUserRoleMapper.selectByRoleId(testRoleId); param.put("testUsers",
			 * userList); instance = runtimeService.startProcessInstanceByKey("EnvProcess",
			 * param); } else { instance =
			 * runtimeService.startProcessInstanceByKey("demandProcess", param);
			 * 
			 * }
			 */

			instance = runtimeService.startProcessInstanceByKey("demandProcess", param);

			requireApply.setProcessId(instance.getId());

		} else {

			sid = requireApply.getId();
			// 删除关联表
			applySystemMapper.deleteByApplyId(sid);
			applyServerMapper.deleteByApplyId(sid);
			applySystemCallMapper.deleteByApplyId(sid);
			applyFieldMapper.deleteByApplyId(sid);
			applyEnvironmentMapper.deleteByApplyId(sid);

		}

		requireApplyMapper.updateByPrimaryKeySelective(requireApply);

		// 循环插入ApplyEnvironment
		for (ApplyEnvironment applyEnvironment : requireApplyDetail.getApplyEnvironmentList()) {
			applyEnvironment.setApplyId(sid);
			if ("01".equals(applyEnvironment.getRequireType()) || "02".equals(applyEnvironment.getRequireType())) {
				applyEnvironment.setConfigStatus("01");
			} else {
				applyEnvironment.setConfigStatus("02");
			}
			applyEnvironmentMapper.insert(applyEnvironment);
		}

		// 循环插入ApplySystem表
		for (ApplySystem applySystem : requireApplyDetail.getApplySystemList()) {
			applySystem.setApplyId(sid);
			applySystem.setStatus("01".equals(applySystem.getRequireType()) ? "01" : "02");
			applySystemMapper.insert(applySystem);
		}

		// 循环插入ApplyServer表

		for (ApplyServerExtend applyServerExtend : requireApplyDetail.getApplyServerList()) {

			if ("01".equals(applyServerExtend.getRequireType())) {
				applyServerExtend.setConfigStatus("01");
			} else {
				SmpServiceKey smpServicekey = new SmpServiceKey();
				smpServicekey.setTransCode(applyServerExtend.getTransCode());
				smpServicekey.setSystemNo(applyServerExtend.getSystemNo());
				SmpService SmpServiceResult = smpServiceMapper.selectByPrimaryKey(smpServicekey);
				applyServerExtend.setConfigStatus("02");
				applyServerExtend.setBusCode(SmpServiceResult.getBusCode());
			}

			applyServerExtend.setApplyId(sid);
			applyServerMapper.insert(applyServerExtend);

			for (ApplyField applyField : applyServerExtend.getApplyFieldList()) {
				applyField.setApplyId(sid);
				applyField.setSystemNo(applyServerExtend.getSystemNo());
				applyField.setTransCode(applyServerExtend.getTransCode());
				applyFieldMapper.insert(applyField);
			}
		}

		// 循环插入ApplySystemCall表
		for (ApplySystemCall applySystemCall : requireApplyDetail.getApplySystemCallList()) {
			applySystemCall
					.setPubCode("01".equals(applySystemCall.getRequireType()) ? null : applySystemCall.getPubCode());
			applySystemCall.setId(sid);
			applySystemCall.setStatus("01".equals(applySystemCall.getRequireType()) ? "01" : "02");

			applySystemCallMapper.insert(applySystemCall);
		}

		if (!Constants.APPLY_TYPE_04.equals(requireApply.getApplyType())) {
			// 判断需求批次表 REQUIREMENT_BATCH 有就修改，没有就添加
			RequirementBatchKey requirementBatchKey = new RequirementBatchKey();

			requirementBatchKey.setQmsNo(requireApply.getQmsNo());
			requirementBatchKey.setBatchNum(requireApply.getBatchNum());

			RequirementBatch requirementBatch2 = requirementBatchMapper.selectByPrimaryKey(requirementBatchKey);

			RequirementBatch requirementBatch = new RequirementBatch();
			requirementBatch.setQmsNo(requireApply.getQmsNo());
			requirementBatch.setBatchNum(requireApply.getBatchNum());
			requirementBatch.setStatus("01");// 需求状态 01 申请 02 受理 03 开发 04 测试
			requirementBatch.setAcceptTime(applyDate);
			// requirementBatch.setDealUser(applyUser);

			if (requirementBatch2 == null || "".equals(requirementBatch2.getQmsNo())) {
				// 没有就添加
				requirementBatch.setCreateTime(applyDate);
				requirementBatchMapper.insertSelective(requirementBatch);

			} else {
				// 修改
				requirementBatch2.setUpdateTime(applyDate);
				requirementBatchMapper.updateByPrimaryKeySelective(requirementBatch2);
			}

			// 添加需求批次时间表 REQUIREMENT_BATCH_TIEM
			RequirementBatchTiem requirementBatchTiem = new RequirementBatchTiem();
			requirementBatchTiem.setQmsNo(requireApply.getQmsNo());
			requirementBatchTiem.setBatchNum(requireApply.getBatchNum());
			requirementBatchTiem.setApplyId(sid);
			requirementBatchTiem.setStatus("01");// 需求状态 01 申请 02 受理 03 开发 04 测试
			requirementBatchTiem.setUpdateTime(applyDate);
			requirementBatchTiem.setDealUser(applyUser);

			requirementBatchTiemMapper.insertSelective(requirementBatchTiem);

		}

		if (!"0".equals(applyStatus)) {
			Task task = taskService.createTaskQuery().processInstanceId(requireApply.getProcessId()).singleResult();

			// 通过角色获取服务管理员
			Map formData = new HashMap();
			formData.put("applyDate", new Date());

			// 获取管理员角色对应user

			List<String> userList = smpUserRoleMapper.selectByRoleId(adminRoleId);

			formData.put("adminUsers", userList);

			// 查询需求信息
			RequirementBatchKey batchKey = new RequirementBatchKey();
			batchKey.setQmsNo(requireApply.getQmsNo());
			batchKey.setBatchNum(requireApply.getBatchNum());

			RequirementBatch requirementBatch = requirementBatchMapper.selectByPrimaryKey(batchKey);
			if (requirementBatch != null && !StringUtil.isBlank(requirementBatch.getDealUser())) {
				List<String> developList = new ArrayList<String>();
				developList.add(requirementBatch.getDealUser());
				formData.put("developUsers", developList);
			} else {
				// 获取开发人员列表
				List<String> developList = smpUserRoleMapper.selectByRoleId(developRoleId);
				formData.put("developUsers", developList);
			}

			formData.put("status", "0");
			logger.info("提交表单数据");
			// formService.submitTaskFormData(task.getId(), formData);

			// logger.info("表单数据提交成功");
			// 提交工单申请
			Map localVar = new HashMap();
			localVar.put("status", "0");
			localVar.put("resultMessage", "提交");

			// Task task =
			// taskService.createTaskQuery().taskId(examine.getTaskId()).singleResult();

			taskService.setVariablesLocal(task.getId(), localVar);
			taskService.complete(task.getId(), formData);

			new Thread(new Runnable() {
				@Override
				public void run() {
					try {
						taskServer.SendMessage(requireApply.getProcessId());
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}).start();

		}

		logger.info(response.getMessage());

		response.setExtend(sid);
		return response;
	}

	/**
	 * 提交附件信息
	 * 
	 * @param requireApplyDetail
	 * @return
	 */

	@RequestMapping("/addAppendix")
	public ResponseMessage<?> addAppendix(MultipartFile[] files, String applyId, String[] fileNameList) {
		ResponseMessage<?> response = new ResponseMessage<>();
		response.setCode("0000");
		response.setMessage("提交成功");
		// 删除不在fileList的附件
		if (fileNameList != null && fileNameList.length > 0) {
			applyAppendixMapper.deleteExcludeFileNames(applyId, fileNameList);
		}
		for (MultipartFile file : files) {
			ApplyAppendixKey key = new ApplyAppendixKey();
			key.setApplyId(applyId);
			key.setFileName(file.getOriginalFilename());
			ApplyAppendix applyAppendix = applyAppendixMapper.selectByPrimaryKey(key);
			if (applyAppendix == null) {
				applyAppendix = new ApplyAppendix();
				applyAppendix.setFileName(file.getOriginalFilename());
				applyAppendix.setApplyId(applyId);
				applyAppendix.setCreateDate(new Date());
				try {
					applyAppendix.setFileContent(file.getBytes());
				} catch (IOException e) {
					logger.error("", e);
				}
				applyAppendixMapper.insert(applyAppendix);
			} else {
				applyAppendix.setCreateDate(new Date());
				try {
					applyAppendix.setFileContent(file.getBytes());
				} catch (IOException e) {
					logger.error("", e);
				}
				applyAppendixMapper.updateByPrimaryKeyWithBLOBs(applyAppendix);
			}

		}
		return response;
	}

	/**
	 * 单个附件提交
	 * 
	 * @param requireApplyDetail
	 * @return
	 */

	@RequestMapping("/addAppendixSingle")
	public ResponseMessage<?> addAppendixSingle(MultipartFile file, String applyId) {
		ResponseMessage<?> response = new ResponseMessage<>();
		response.setCode("0000");
		response.setMessage("提交成功");

		ApplyAppendixKey key = new ApplyAppendixKey();
		key.setApplyId(applyId);
		key.setFileName(file.getOriginalFilename());
		ApplyAppendix applyAppendix = applyAppendixMapper.selectByPrimaryKey(key);
		if (applyAppendix == null) {
			applyAppendix = new ApplyAppendix();
			applyAppendix.setFileName(file.getOriginalFilename());
			applyAppendix.setApplyId(applyId);
			applyAppendix.setCreateDate(new Date());
			try {
				applyAppendix.setFileContent(file.getBytes());
			} catch (IOException e) {
				logger.error("", e);
			}
			applyAppendixMapper.insert(applyAppendix);
		} else {
			applyAppendix.setCreateDate(new Date());
			try {
				applyAppendix.setFileContent(file.getBytes());
			} catch (IOException e) {
				logger.error("", e);
			}
			applyAppendixMapper.updateByPrimaryKeyWithBLOBs(applyAppendix);
		}
		return response;
	}

	/**
	 * 单个附件提交
	 * 
	 * @param requireApplyDetail
	 * @return
	 */

	@RequestMapping("/deleteAppendixSingle")
	public ResponseMessage<?> deleteAppendixSingle(@RequestBody ApplyAppendixKey appendixKey) {
		ResponseMessage<?> response = new ResponseMessage<>();
		response.setCode("0000");
		response.setMessage("提交成功");
		applyAppendixMapper.deleteByPrimaryKey(appendixKey);
		return response;
	}

	/**
	 * 提交附件信息
	 * 
	 * @param requireApplyDetail
	 * @return
	 * @throws IOException
	 */

	@RequestMapping("/appendixDown")
	public void addAppendix(@RequestBody ApplyAppendix applyAppendix) throws IOException {
		applyAppendix = applyAppendixMapper.selectByPrimaryKey(applyAppendix);
		OutputStream out = response.getOutputStream();
		out.write(applyAppendix.getFileContent());
		out.flush();
		out.close();
	}

	/**
	 * 工单申请保存
	 * 
	 * @param requireApplyDetail
	 * @return
	 */
	@Transactional
	@RequestMapping("/saveAll")
	public ResponseMessage<String> saveAll(@RequestBody RequireApplyDetail requireApplyDetail) {
		ResponseMessage<String> response = new ResponseMessage<String>();
		response.setCode("0000");
		response.setMessage("添加成功");

		Date applyDate = new Date();
		String applyUser = request.getHeader("userName");

		int id = requireApplyMapper.getId();
		String sid = null;
		RequireApply requireApply = requireApplyDetail.getRequireApply();

		// 校验
		for (ApplyServerExtend applyServerExtend2 : requireApplyDetail.getApplyServerList()) {

			// 对ApplyServer进行校验
			// 查询ApplyServer是否有未完成流程
			ApplyServerExtend applyServer = new ApplyServerExtend();
			applyServer.setTransCode(applyServerExtend2.getTransCode());
			applyServer.setSystemNo(applyServerExtend2.getSystemNo());
			applyServer.setRequireType(applyServerExtend2.getRequireType());
			if (requireApply.getId() != null && !"".equals(requireApply.getId())) {
				applyServer.setApplyId(requireApply.getId());
			}
			applyServer.setQmsNo(requireApply.getQmsNo());
			applyServer.setBatchNum(requireApply.getBatchNum());

			// 调用检验方法
			ResponseMessage<?> check = getServerCheck(applyServer);
			if ("0001".equals(check.getCode())) {
				response.setCode("0001");
				response.setMessage(check.getMessage());
				return response;
			}
		}

		// 校验服务调用
		for (ApplySystemCall applySystemCall2 : requireApplyDetail.getApplySystemCallList()) {

			if (requireApply.getId() != null && !"".equals(requireApply.getId())) {
				applySystemCall2.setId(requireApply.getId());
			}
			// 调用检验方法
			ResponseMessage<?> applySystemCallCheck = getSystemCallCheck(applySystemCall2,
					requireApplyDetail.getRequireApply().getQmsNo());
			if ("0001".equals(applySystemCallCheck.getCode())) {
				response.setCode("0001");
				response.setMessage(applySystemCallCheck.getMessage());
				return response;
			}

		}

		// 系统维护校验
		for (ApplySystem applySystem2 : requireApplyDetail.getApplySystemList()) {

			if (requireApply.getId() != null && !"".equals(requireApply.getId())) {
				applySystem2.setApplyId(requireApply.getId());
			}
			// 调用检验方法
			ResponseMessage<?> applySystemCheck = getSystemCheck(applySystem2);
			if ("0001".equals(applySystemCheck.getCode())) {
				response.setCode("0001");
				response.setMessage(applySystemCheck.getMessage());
				return response;
			}
		}

		// 状态：10 待提交
		requireApply.setStatus("10");

		// 保存时如果是之前没有保存过的则插入新数据
		if (requireApply.getId() == null || "".equals(requireApply.getId())) {
			// sid = new SimpleDateFormat("yyyyMmdd").format(new
			// Date())+String.format("%08d", id);

			requireApply.setApplyDate(applyDate);
			requireApply.setApplyUser(applyUser);

			String preFix = "";

			switch (requireApply.getApplyType()) {
			case Constants.APPLY_TYPE_01:
				preFix = Constants.APPLY_PREFIX_01;
				break;
			case Constants.APPLY_TYPE_02:
				preFix = Constants.APPLY_PREFIX_02;
				break;
			case Constants.APPLY_TYPE_03:
				preFix = Constants.APPLY_PREFIX_03;
				break;
			case Constants.APPLY_TYPE_04:
				preFix = Constants.APPLY_PREFIX_04;
				break;
			default:
				preFix = Constants.APPLY_PREFIX_01;
				break;
			}

			sid = preFix + new SimpleDateFormat("yyyyMMdd").format(new Date()) + String.format("%04d", id);

			requireApply.setId(sid);

			int a = requireApplyMapper.insert(requireApply);

			// 新建流程数据
			Map param = new HashMap<>();
			param.put("applyUser", applyUser);
			param.put("qmsNo", requireApply.getQmsNo());
			param.put("qmsName", requireApply.getQmsName());
			param.put("sid", sid);
			param.put("applyType", requireApply.getApplyType());

			ProcessInstance instance = null;
//    		if(Constants.APPLY_TYPE_02.equals(requireApply.getApplyType())) {
//    			//查询服务方系统负责人
//    			String regSysNo = requireApply.getRegSysNo();
//    			
//    			SmpSystem smpSystem = smpSystemMapper.selectByPrimaryKey(regSysNo);
//    			param.put("serverSystemUser", smpSystem.getSystemResponsibleMan());
//    			
//        		 instance = runtimeService.startProcessInstanceByKey("systemCallProcess", param);
//
//    		}else if(Constants.APPLY_TYPE_04.equals(requireApply.getApplyType())) {

			/*
			 * if (Constants.APPLY_TYPE_04.equals(requireApply.getApplyType())) {
			 * 
			 * //查询服务方系统负责人 String regSysNo = requireApply.getRegSysNo();
			 * 
			 * SmpSystem smpSystem = smpSystemMapper.selectByPrimaryKey(regSysNo);
			 * param.put("serverSystemUser", smpSystem.getSystemResponsibleMan());
			 * 
			 *
			 * 
			 * // 查询测试管理员 List<String> userList =
			 * smpUserRoleMapper.selectByRoleId(testRoleId); param.put("testUsers",
			 * userList); instance = runtimeService.startProcessInstanceByKey("EnvProcess",
			 * param); } else { instance =
			 * runtimeService.startProcessInstanceByKey("demandProcess", param);
			 * 
			 * }
			 */

			instance = runtimeService.startProcessInstanceByKey("demandProcess", param);

			requireApply.setProcessId(instance.getId());

			

		} else {
			// 保存时如果是之前保存过的则 主表不变 删除关联表重新插入

			sid = requireApply.getId();
			// 删除关联表
			applySystemMapper.deleteByApplyId(sid);
			applyServerMapper.deleteByApplyId(sid);
			applySystemCallMapper.deleteByApplyId(sid);
			applyFieldMapper.deleteByApplyId(sid);
			applyEnvironmentMapper.deleteByApplyId(sid);
		}

		requireApplyMapper.updateByPrimaryKeySelective(requireApply);

		// 循环插入ApplySystem表
		for (ApplySystem applySystem : requireApplyDetail.getApplySystemList()) {
			applySystem.setApplyId(sid);
			applySystem.setStatus("01".equals(applySystem.getRequireType()) ? "01" : "02");
			applySystemMapper.insert(applySystem);
		}

		for (ApplyEnvironment applyEnvironment : requireApplyDetail.getApplyEnvironmentList()) {
			applyEnvironment.setApplyId(sid);
			if ("01".equals(applyEnvironment.getRequireType()) || "02".equals(applyEnvironment.getRequireType())) {
				applyEnvironment.setConfigStatus("01");
			} else {
				applyEnvironment.setConfigStatus("02");
			}
			applyEnvironmentMapper.insert(applyEnvironment);
		}

		// 循环插入ApplyServer表
		for (ApplyServerExtend applyServerExtend : requireApplyDetail.getApplyServerList()) {

			applyServerExtend.setApplyId(sid);
			applyServerMapper.insert(applyServerExtend);

			for (ApplyField applyField : applyServerExtend.getApplyFieldList()) {
				applyField.setApplyId(sid);
				applyField.setSystemNo(applyServerExtend.getSystemNo());
				applyField.setTransCode(applyServerExtend.getTransCode());
				applyFieldMapper.insert(applyField);
			}
		}

		// 循环插入ApplySystemCall表
		for (ApplySystemCall applySystemCall : requireApplyDetail.getApplySystemCallList()) {
			applySystemCall.setId(sid);
			applySystemCall.setPubCode(null);
			applySystemCall.setStatus("01".equals(applySystemCall.getRequireType()) ? "01" : "02");
			applySystemCallMapper.insert(applySystemCall);
		}

		logger.info(response.getMessage());
		response.setExtend(sid);
		return response;
	}

	/**
	 * 工单申请撤销
	 * 
	 * @param requireApply
	 * @return
	 */
	@Transactional
	@RequestMapping("/delAll")
	public ResponseMessage<?> delAll(@RequestBody RequireApply requireApply) {

		ResponseMessage<?> response = new ResponseMessage();
		response.setCode("0000");
		response.setMessage("撤销成功");

		requireApply.setStatus("1");

		requireApplyMapper.updateByPrimaryKeySelective(requireApply);

		Task task = taskService.createTaskQuery().processInstanceId(requireApply.getProcessId()).singleResult();

		// 通过角色获取服务管理员
		Map formData = new HashMap();
//		formData.put("applyDate", new Date());
		formData.put("adminUser", "huangjie");
		formData.put("status", "1");
		logger.info("撤销表单数据");
		// formService.submitTaskFormData(task.getId(), formData);

		// logger.info("表单数据提交成功");
		// 提交工单申请
		Map localVar = new HashMap();
		localVar.put("status", "1");
		localVar.put("resultMessage", "已撤销");

		// Task task =
		// taskService.createTaskQuery().taskId(examine.getTaskId()).singleResult();

		taskService.setVariablesLocal(task.getId(), localVar);

		taskService.complete(task.getId(), formData);

		logger.info(response.getMessage());
		return response;

	}

	/**
	 * 查询工单申请明细
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping("/selectAllByApplyId")
	public ResponseMessage<RequireApplyDetail> selectAllByApplyId(
			@RequestParam(value = "id", defaultValue = "") String id) {
		ResponseMessage<RequireApplyDetail> responseMessage = new ResponseMessage<RequireApplyDetail>();

		RequireApply requireApply = requireApplyMapper.selectByPrimaryKey(id);

		List<ApplySystem> applySystemList = applySystemMapper.selectByApplyId(id);

		List<ApplyServerExtend> applyServerList = applyServerMapper.selectByApplyId(id);

		List<ApplyEnvironment> listApplyEnvironment = applyEnvironmentMapper.getApplyEnvironmentList(id);

		for (ApplyServerExtend applyServer : applyServerList) {

			ApplyField applyField = new ApplyField();
			applyField.setApplyId(applyServer.getApplyId());
			applyField.setTransCode(applyServer.getTransCode());
			applyField.setSystemNo(applyServer.getSystemNo());
			List<ApplyField> applyFieldList = applyFieldMapper.selectByApplyIdAndTransCode(applyField);

			applyServer.setApplyFieldList(applyFieldList);

		}

		List<ApplySystemCall> applySystemCallList = applySystemCallMapper.selectByApplyId(id);

		List<ApplyAppendix> applyAppendixList = applyAppendixMapper.selectByApplyId(id);

		RequireApplyDetail requireApplyDetail = new RequireApplyDetail();
		requireApplyDetail.setRequireApply(requireApply);
		requireApplyDetail.setApplySystemList(applySystemList);
		requireApplyDetail.setApplyServerList(applyServerList);
		requireApplyDetail.setApplySystemCallList(applySystemCallList);
		requireApplyDetail.setApplyAppendixList(applyAppendixList);
		requireApplyDetail.setApplyEnvironmentList(listApplyEnvironment);

		responseMessage.setExtend(requireApplyDetail);
		logger.info(responseMessage.getMessage());
		return responseMessage;
	}

	// 服务调用配置
	@RequestMapping("/updateApplySystemCallInfo")
	public ResponseMessage<?> updateApplySystemCallInfo(@RequestBody ApplySystemCall applySystemCall) {
		ResponseMessage<?> responseMessage = new ResponseMessage<>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("服务调用配置成功！");
		applySystemCall.setStatus("02");
		int code = applySystemCallMapper.updateByPrimaryKeySelective(applySystemCall);

		// proxyPath保存到SYSTEM_CALL_PROXY_PATH表 没有的就添加
		int num = systemCallProxyPathMapper.selectByCount(applySystemCall.getProxyPath());

		if (num == 0) {
			SystemCallProxyPath systemCallProxyPath = new SystemCallProxyPath();
			systemCallProxyPath.setProxyPath(applySystemCall.getProxyPath());
			systemCallProxyPathMapper.insert(systemCallProxyPath);
		}

		logger.info(responseMessage.getMessage());
		return responseMessage;

	}

	/**
	 * 修改服务调用信息
	 * 
	 * @param smpSystemCall
	 * @return
	 */
	@RequestMapping("/updateSystemCallInfo")
	public ResponseMessage<?> updateSystemCallInfo(@RequestBody SmpSystemCall smpSystemCall) {
		ResponseMessage<?> responseMessage = new ResponseMessage<>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("修改调用信息成功！");

		int code = smpSystemCallMapper.updateByPrimaryKeySelective(smpSystemCall);

		// proxyPath保存到SYSTEM_CALL_PROXY_PATH表 没有的就添加
		int num = systemCallProxyPathMapper.selectByCount(smpSystemCall.getProxyPath());

		if (num == 0) {
			SystemCallProxyPath systemCallProxyPath = new SystemCallProxyPath();
			systemCallProxyPath.setProxyPath(smpSystemCall.getProxyPath());
			systemCallProxyPathMapper.insert(systemCallProxyPath);
		}

		logger.info(responseMessage.getMessage());
		return responseMessage;

	}

	/**
	 * 修改服务调用信息
	 * 
	 * @param smpSystemCall
	 * @return
	 */
	@RequestMapping("/addSystemCallInfo")
	public ResponseMessage<?> addSystemCallInfo(@RequestBody SmpSystemCallExtend smpSystemCall) {
		// AUTO

		ResponseMessage<?> responseMessage = new ResponseMessage<>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("新增服务调用信息");

		// 服务调用是否存在SmpSystemCall
		SmpSystemCallExtend smpSystemCallExtend = new SmpSystemCallExtend();
		smpSystemCallExtend.setBusCode(smpSystemCall.getBusCode());
		smpSystemCallExtend.setPubSysCode(smpSystemCall.getPubSysCode());
		smpSystemCallExtend.setRegSysCode(smpSystemCall.getRegSysCode());

		int a = smpSystemCallMapper.selectByCount(smpSystemCallExtend);

		if (a > 0) { // 新增表有
			responseMessage.setCode("0001");
			responseMessage.setMessage("请求系统[" + smpSystemCall.getPubSysCode() + "]调用服务系统["
					+ smpSystemCall.getRegSysCode() + "]交易[" + smpSystemCall.getTransCode() + "]关系已存在");
			return responseMessage;
		}

		ApplySystemCall applySystemCall = new ApplySystemCall();

		// applySystemCall.setBusCode(smpSystemCall.getBusCode());
		applySystemCall.setPubSysCode(smpSystemCall.getPubSysCode());
		applySystemCall.setRegSysCode(smpSystemCall.getRegSysCode());
		applySystemCall.setTransCode(smpSystemCall.getTransCode());

		// 查询ApplySystemCall是否有未完成流程
		int applySystemCallInt = applySystemCallMapper.selectByCount(applySystemCall);
		;

		if (applySystemCallInt > 0) {
			responseMessage.setCode("0001");
			responseMessage.setMessage("请求系统[" + applySystemCall.getPubSysCode() + "]调用服务系统["
					+ applySystemCall.getRegSysCode() + "]交易[" + smpSystemCallExtend.getTransCode() + "]存在未完成流程");
			return responseMessage;
		}

		// 如果服务未上线则只能在服务对应的需求里提服务调用
		SmpServiceKey smpServiceKey = new SmpServiceKey();
		smpServiceKey.setSystemNo(smpSystemCall.getRegSysCode());
		smpServiceKey.setTransCode(smpSystemCall.getTransCode());
		SmpService smpService = smpServiceMapper.selectByPrimaryKey(smpServiceKey);

		if (smpService == null) {
			responseMessage.setCode("0001");
			responseMessage.setMessage(
					"系统[" + applySystemCall.getRegSysCode() + "]交易[" + applySystemCall.getTransCode() + "]不存在");
			return responseMessage;
		}

		int code = smpSystemCallMapper.insert(smpSystemCall);
		logger.info(responseMessage.getMessage());
		return responseMessage;

	}

	// 系统注册配置
	@RequestMapping("/updateApplySystemInfo")
	public ResponseMessage<?> updateApplySystemInfo(@RequestBody ApplySystem applySystem) {
		ResponseMessage<?> responseMessage = new ResponseMessage<>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("系统注册配置成功！");

		int code = applySystemMapper.updateByPrimaryKeySelective(applySystem);
		logger.info(responseMessage.getMessage());
		return responseMessage;
	}

	// 服务注册配置
	@RequestMapping("/updateApplyServerInfo")
	public ResponseMessage<?> updateApplyServerInfo(@RequestBody ApplyServer applyServer) {
		ResponseMessage<?> responseMessage = new ResponseMessage<>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("服务注册配置成功！");

		applyServer.setConfigStatus(Constants.CONFIG_STATUS_02);

		int code = applyServerMapper.updateByPrimaryKeySelective(applyServer);
		logger.info(responseMessage.getMessage());
		return responseMessage;
	}

	/**
	 * 配置环境维护信息
	 * 
	 * @param applyEnvironment
	 * @return
	 */
	@RequestMapping("/updateApplyEnvironmentInfo")
	public ResponseMessage<?> updateApplyEnvironmentInfo(@RequestBody ApplyEnvironment applyEnvironment) {
		ResponseMessage<?> responseMessage = new ResponseMessage<>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("环境维护配置成功！");

		applyEnvironment.setConfigStatus(Constants.CONFIG_STATUS_02);

		int code = applyEnvironmentMapper.updateByPrimaryKeySelective(applyEnvironment);
		logger.info(responseMessage.getMessage());
		return responseMessage;
	}

	/**
	 * 自动生成服务编码（R值）
	 * 
	 * @param systemNo
	 * @return
	 */
	@RequestMapping("/autoGenerateBusCode")
	public ResponseMessage<String> autoGenerateBusCode(@RequestParam String systemNo) {
		ResponseMessage<String> responseMessage = new ResponseMessage<String>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("服务编码（R值）生成成功！");
		String busCode;
		int id = applyServerMapper.getId();
		if (systemNo.length() == 9) {
			busCode = "R000" + "10" + String.format("%06d", id);
		} else {
			busCode = "R" + systemNo + "10" + String.format("%06d", id);
		}

		responseMessage.setExtend(busCode);
		logger.info(responseMessage.getMessage());
		return responseMessage;
	}

	/**
	 * 完成开发确认
	 * 
	 * @param applyId
	 * @param resultMessage
	 * @return
	 */
	@Transactional
	@RequestMapping("/developConfirm")
	public ResponseMessage<?> developConfirm(@RequestParam String applyId, @RequestParam String resultMessage) {
		ResponseMessage<?> responseMessage = new ResponseMessage<>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("开发完成");

		RequireApply requireApply = requireApplyMapper.selectByPrimaryKey(applyId);

		if (Constants.APPLY_TYPE_04.equals(requireApply.getApplyType())) {
			int configNum = applyEnvironmentMapper.getConfigStatus(applyId);
			if (configNum > 0) {
				/*
				 * responseMessage.setCode("0001"); responseMessage.setMessage("存在未配置的环境维护信息！");
				 * return responseMessage;
				 */
				throw new SmpException("0001", "存在未配置的环境维护信息！");
			}
		}

		SmpService smpService = new SmpService();
		// SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date time = new Date();
		if (Constants.APPLY_TYPE_01.equals(requireApply.getApplyType())) {
			List<ApplyServerExtend> listApplyServerExtend = applyServerMapper.selectByApplyId(applyId);
			for (ApplyServerExtend applyServerExtend : listApplyServerExtend) {
				if (Constants.CONFIG_STATUS_01.equals(applyServerExtend.getConfigStatus())) {
					throw new SmpException("0001", "存在未配置交易");
				}
			}

			smpService.setCreateTime(time);
			smpService.setStatus("01");
			smpService.setQmsNo(requireApply.getQmsNo());
			smpService.setApplicationTime(requireApply.getapplyDate());
			smpService.setProposer(requireApply.getApplyUser());
			smpService.setDeveloper(request.getHeader("userName"));
			smpService.setBatchNum(requireApply.getBatchNum());
			try {
				for (ApplyServerExtend applyServerExtend : listApplyServerExtend) {
					ObjectUtil.copyBeans(applyServerExtend, smpService);
					smpService.setStatus("01");
					if (Constants.REQUIRE_TYPE_01.equals(applyServerExtend.getRequireType())) {
						// 新增
						smpServiceMapper.insert(smpService);
						// 根据申请ID，系统编号、交易吗查询apply——filed
						ApplyField field = new ApplyField();
						field.setApplyId(applyId);
						field.setSystemNo(applyServerExtend.getSystemNo());
						field.setTransCode(applyServerExtend.getTransCode());
						List<ApplyField> fieldList = applyFieldMapper.selectByApplyIdAndTransCode(field);
						for (ApplyField field1 : fieldList) {
							SmpField smpField = new SmpField();
							ObjectUtil.copyBeans(field1, smpField);
							smpFieldMapper.insert(smpField);

						}

					} else if (Constants.REQUIRE_TYPE_02.equals(applyServerExtend.getRequireType())) {
						// 修改
						// 插入历史表
						SmpService smpService1 = smpServiceMapper.selectByPrimaryKey(smpService);
						SmpServiceHis smpServiceHis = new SmpServiceHis();
						ObjectUtil.copyBeans(smpService1, smpServiceHis);
						int id = smpServiceHisMapper.getId();
						smpServiceHis.setId(Integer.toString(id));
						smpServiceHisMapper.insertSelective(smpServiceHis);

						smpServiceMapper.updateByPrimaryKeySelective(smpService);
						// 判断是否交易码变更
						String newTransCode = applyServerExtend.getNewTransCode();
						if (!StringUtil.isBlank(newTransCode)) {

							SmpServiceExtend serviceExtend = new SmpServiceExtend();

							serviceExtend.setTransCode(applyServerExtend.getTransCode());
							serviceExtend.setSystemNo(applyServerExtend.getSystemNo());
							serviceExtend.setNewTransCode(newTransCode);
							smpServiceMapper.updateTransCodeByPrimaryKey(serviceExtend);
						}

						// 插入字段历史表
						SmpField smpField1 = new SmpField();
						smpField1.setTransCode(applyServerExtend.getTransCode());
						smpField1.setSystemNo(applyServerExtend.getSystemNo());

						List<SmpField> smpFieldList = smpFieldMapper.getFieldListByNoCode(smpField1);

						smpFieldList.forEach(field -> {
							smpFieldHis smpFieldHis = new smpFieldHis();
							ObjectUtil.copyBeans(field, smpFieldHis);
							smpFieldHis.setServiceHisId(Integer.toString(id));
							fieldHisMapper.insertSelective(smpFieldHis);
						});

						// 删除SmpField

						smpFieldMapper.deleteByTransCodeAndSystemNo(smpField1);

						// 根据申请ID，系统编号、交易吗查询apply——filed
						ApplyField field = new ApplyField();
						field.setApplyId(applyId);
						field.setSystemNo(applyServerExtend.getSystemNo());
						field.setTransCode(applyServerExtend.getTransCode());
						List<ApplyField> fieldList = applyFieldMapper.selectByApplyIdAndTransCode(field);
						for (ApplyField field1 : fieldList) {
							SmpField smpField = new SmpField();
							ObjectUtil.copyBeans(field1, smpField);
							if (!StringUtil.isBlank(newTransCode)) {
								smpField.setTransCode(newTransCode);
							}
							smpFieldMapper.insert(smpField);
						}

					} else if (Constants.REQUIRE_TYPE_03.equals(applyServerExtend.getRequireType())) {
						// 删除
						SmpService smpService1 = smpServiceMapper.selectByPrimaryKey(smpService);
						SmpServiceHis smpServiceHis = new SmpServiceHis();
						ObjectUtil.copyBeans(smpService1, smpServiceHis);
						int id = smpServiceHisMapper.getId();
						smpServiceHis.setId(Integer.toString(id));
						smpServiceHisMapper.insertSelective(smpServiceHis);

						smpServiceMapper.deleteByPrimaryKey(smpService);

						// 插入字段历史表
						SmpField smpField1 = new SmpField();
						smpField1.setTransCode(applyServerExtend.getTransCode());
						smpField1.setSystemNo(applyServerExtend.getSystemNo());

						List<SmpField> smpFieldList = smpFieldMapper.getFieldListByNoCode(smpField1);

						smpFieldList.forEach(field -> {
							smpFieldHis smpFieldHis = new smpFieldHis();
							ObjectUtil.copyBeans(field, smpFieldHis);
							smpFieldHis.setServiceHisId(Integer.toString(id));
							fieldHisMapper.insertSelective(smpFieldHis);
						});

						// 删除SmpField

						smpFieldMapper.deleteByTransCodeAndSystemNo(smpField1);

						// 根据申请ID，系统编号、交易吗查询apply——filed
						/*
						 * ApplyField field = new ApplyField(); field.setApplyId(applyId);
						 * field.setSystemNo(applyServerExtend.getSystemNo());
						 * field.setTransCode(applyServerExtend.getTransCode()); List<ApplyField>
						 * fieldList = applyFieldMapper.selectByApplyIdAndTransCode(field);
						 * smpFieldMapper.deleteByTransCodeAndSystemNo(field);
						 */
						/*
						 * for(ApplyField field1:fieldList) { SmpField smpField = new SmpField();
						 * ObjectUtil.copyBeans(field1, smpField);
						 * smpFieldMapper.deleteByPrimaryKey(smpField); }
						 */

					}
				}
				responseMessage.setMessage("服务注册成功!");
			} catch (Exception e) {
				/*
				 * responseMessage.setCode("0001"); responseMessage.setMessage("服务注册失败!");
				 * return responseMessage;
				 */
				throw new SmpException("0001", "服务注册失败" + e.getMessage());
			}
		} else if (Constants.APPLY_TYPE_02.equals(requireApply.getApplyType())) {
			List<ApplySystemCall> listApplySystemCall = applySystemCallMapper.selectByApplyId(applyId);
			for (ApplySystemCall applySystemCall : listApplySystemCall) {
				if (Constants.CONFIG_STATUS_01.equals(applySystemCall.getStatus())) {
					throw new SmpException("0001", "存在未配置交易");
				}
			}

			SmpSystemCall smpSystemCall = new SmpSystemCall();
			smpSystemCall.setCreateTime(time);
			smpSystemCall.setAssociatedRequirement(requireApply.getQmsNo());
			smpSystemCall.setStatus("01");
			smpSystemCall.setBatchNum(requireApply.getBatchNum());
			try {
				for (ApplySystemCall applySystemCall : listApplySystemCall) {
					ObjectUtil.copyBeans(applySystemCall, smpSystemCall);

					smpSystemCall.setStatus("01");

					if (Constants.REQUIRE_TYPE_01.equals(applySystemCall.getRequireType())) {
						// 新增
						smpSystemCallMapper.insert(smpSystemCall);

					} else if (Constants.REQUIRE_TYPE_02.equals(applySystemCall.getRequireType())) {
						// 修改
						smpSystemCallMapper.updateByPrimaryKeySelective(smpSystemCall);

					} else if (Constants.REQUIRE_TYPE_03.equals(applySystemCall.getRequireType())) {
						// 删除
						smpSystemCallMapper.deleteByPrimaryKey(smpSystemCall);

					}
				}
				responseMessage.setMessage("服务调用成功!");
			} catch (Exception e) {
				/*
				 * e.printStackTrace(); responseMessage.setCode("0001");
				 * responseMessage.setMessage("服务调用失败!"); return responseMessage;
				 */
				throw new SmpException("0001", "服务调用失败", e);
			}
		} else if (Constants.APPLY_TYPE_03.equals(requireApply.getApplyType())) {
			List<ApplySystem> listApplySystem = applySystemMapper.selectByApplyId(applyId);
			
			for(ApplySystem applySystem:listApplySystem) {
				if (Constants.CONFIG_STATUS_01.equals(applySystem.getStatus())) {
					throw new SmpException("0001", "存在未配置系统");
				}
			}
			
			
			SmpSystem smpSystem = new SmpSystem();
			smpSystem.setAssociatedRequirement(requireApply.getQmsNo());
			smpSystem.setCreateTime(time);
			smpSystem.setSystemStatus("01");
			smpSystem.setBatchNum(requireApply.getBatchNum());
			try {
				for (ApplySystem applySystem : listApplySystem) {
					ObjectUtil.copyBeans(applySystem, smpSystem);
//					smpServiceManagementSystemMapper.insert(smpSystem);

					if (Constants.REQUIRE_TYPE_01.equals(applySystem.getRequireType())) {
						// 新增
						smpServiceManagementSystemMapper.insert(smpSystem);

					} else if (Constants.REQUIRE_TYPE_02.equals(applySystem.getRequireType())) {
						// 修改
						smpServiceManagementSystemMapper.updateByPrimaryKeySelective(smpSystem);

					} else if (Constants.REQUIRE_TYPE_03.equals(applySystem.getRequireType())) {
						// 删除
						smpServiceManagementSystemMapper.deleteByPrimaryKey(smpSystem.getSystemNo());

					}

				}
				systemCache.init();

				responseMessage.setMessage("系统注册成功!");
			} catch (Exception e) {
				throw new SmpException("0001", "系统注册失败", e);
				/*
				 * e.printStackTrace(); responseMessage.setCode("0001");
				 * responseMessage.setMessage("系统注册失败!"); return responseMessage;
				 */
			}
		} else if (Constants.APPLY_TYPE_04.equals(requireApply.getApplyType())) {
			List<ApplyEnvironment> listApplyEnvironment = applyEnvironmentMapper.getApplyEnvironmentList(applyId);
			SmpEnvironment smpEnvironment = new SmpEnvironment();
			try {
				for (ApplyEnvironment applyEnvironment : listApplyEnvironment) {

					ObjectUtil.copyBeans(applyEnvironment, smpEnvironment);
					if ("01".equals(applyEnvironment.getRequireType())) {
						smpEnvironment.setStatus("01");
						smpEnvironmentMapper.insert(smpEnvironment);
					} else if ("02".equals(applyEnvironment.getRequireType())) {
						smpEnvironment.setStatus("02");
						smpEnvironmentMapper.updateByPrimaryKey(smpEnvironment);
						smpEnvironment.setSystemCurrentAddr(applyEnvironment.getSystemTargetAddr());

						SmpEnvironment smpEnvironment1 = smpEnvironmentMapper.selectByPrimaryKey(smpEnvironment);
						smpEnvironment.setStatus("01");
						if (smpEnvironment1 == null) {
							smpEnvironmentMapper.insert(smpEnvironment);
						} else {
							smpEnvironmentMapper.updateByPrimaryKey(smpEnvironment);
						}
					} else if ("03".equals(applyEnvironment.getRequireType())) {
						smpEnvironmentMapper.deleteByPrimaryKey(smpEnvironment);
					}

				}
			} catch (Exception e) {
				/*
				 * e.printStackTrace(); responseMessage.setCode("0001");
				 * responseMessage.setMessage("环境注册失败!"); return responseMessage;
				 */

				throw new SmpException("0001", "环境注册失败", e);
			}

		}

		Map formData = new HashMap();
		formData.put("status", "8");
		Map localVar = new HashMap();
		localVar.put("status", "8");
		localVar.put("resultMessage", resultMessage);
		Task task = taskService.createTaskQuery().includeProcessVariables().processInstanceId(requireApply.getProcessId()).singleResult();
		taskService.setVariablesLocal(task.getId(), localVar);
		taskService.complete(task.getId(), formData);
		

		new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					taskServer.SendMessage1(task);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}).start();
		

		/*
		 * task =
		 * taskService.createTaskQuery().processInstanceId(requireApply.getProcessId()).
		 * singleResult(); // task.ca List<IdentityLink> identityLinks =
		 * taskService.getIdentityLinksForTask(task.getId()); for (IdentityLink
		 * identityLink : identityLinks) { String UserId = identityLink.getUserId();
		 * logger.info("用户Id" + UserId); }
		 */
		// RequireApply requireApply = new RequireApply();
		requireApply.setStatus("8");
		requireApplyMapper.updateStatusByID(requireApply);
		return responseMessage;

	}

	/**
	 * 服务维护导入
	 * 
	 * @param file
	 * @return
	 */

	@RequestMapping("/getFileByExcel")
	public ResponseMessage<List<ApplyServerExtend>> getFileByExcel(MultipartFile file) {

		ResponseMessage<List<ApplyServerExtend>> response = new ResponseMessage<List<ApplyServerExtend>>();
		response.setCode("0000");
		response.setMessage("导入成功！");

		List<ApplyServerExtend> applyServerExtendList = new ArrayList<>();

		try {
			Workbook workbook = new XSSFWorkbook(file.getInputStream());
			// 获取工作表名称是Index
			Sheet sheet = workbook.getSheet("目录");
			
			//获取模板版本号
			String version = "";
			try {
				version = sheet.getRow(0).getCell(1).getStringCellValue();
			}catch (Exception e) {
				// TODO: handle exception
			}
			
			if(!templateversion.equals(version)) {
				response.setCode("0001");
				response.setMessage("模板版本不一致，请使用最新模板");
				return response;
			}
			for (int i = 2; i < sheet.getPhysicalNumberOfRows(); i++) {

				Row row = sheet.getRow(i);// 行从第三行开始
				String systemNo = "";
				try {
					systemNo = row.getCell(0).getStringCellValue();
				} catch (Exception e) {
					try {
						systemNo = Integer.toString((int) row.getCell(0).getNumericCellValue());
					} catch (Exception e1) {
						// TODO: handle exception
					}
				}

				// 没有值得时候跳出循环
				if (row == null || row.getCell(0) == null || "".equals(systemNo)) {
					break;
				}
				ApplyServerExtend applyServerExtend = new ApplyServerExtend();

				// 系统编码

				SmpSystem smpSystem = SmpSystemCache.getSystem(systemNo);
				if (smpSystem == null) {
					response.setCode("0001");
					response.setMessage("系统不存在");
					break;
				}

				applyServerExtend.setSystemNo(systemNo);
				applyServerExtend.setMsgAgreement(smpSystem.getMsgAgreement());
				applyServerExtend.setMsgCode(smpSystem.getMsgCode());
//						applyServerExtend.setTransName(row.getCell(1).getStringCellValue());

				// 机构号
				try {
					applyServerExtend.setSystemOrg(row.getCell(2).getStringCellValue());
				} catch (Exception e) {
					try {
						applyServerExtend.setSystemOrg(Integer.toString((int) row.getCell(2).getNumericCellValue()));
					} catch (Exception e1) {
						// TODO: handle exception
					}
				}

				String transCode = null;

				try {
					transCode = row.getCell(3).getStringCellValue();
				} catch (Exception e) {
					try {
						transCode = Integer.toString((int) row.getCell(3).getNumericCellValue());
						;
					} catch (Exception e1) {

					}
				}

				applyServerExtend.setTransCode(transCode);

				try {
					applyServerExtend.setTransName(row.getCell(4).getStringCellValue());
				} catch (Exception e1) {
					// TODO: handle exception
				}

				/*
				 * try { applyServerExtend.setMsgAgreement(row.getCell(5).getStringCellValue());
				 * } catch (Exception e1) { // TODO: handle exception }
				 */

				// 报文编码 01 utf-8 02 gbk
				/*
				 * if("utf-8".equals(row.getCell(6).getStringCellValue())) {
				 * applyServerExtend.setMsgCode("01"); }else if
				 * ("gbk".equals(row.getCell(6).getStringCellValue())) {
				 * applyServerExtend.setMsgCode("02"); }
				 */
				/*
				 * try { String msgCode = DataDictionaryCache.getItemCode("SMP0004",
				 * row.getCell(6).getStringCellValue()); applyServerExtend.setMsgCode(msgCode);
				 * } catch (Exception e1) { // TODO: handle exception }
				 */

//						applyServerExtend.setMsgCode(row.getCell(6).getStringCellValue());

				try {

					applyServerExtend.setEsbAddr(row.getCell(7).getStringCellValue());
				} catch (Exception e1) {
					// TODO: handle exception
				}

				try {
					applyServerExtend.setTestAddr(row.getCell(8).getStringCellValue());
				} catch (Exception e1) {
					// TODO: handle exception
				}

				// 生产URL
//						applyServerExtend.setProdAddr(row.getCell(9).getStringCellValue());

				// 外部可见 01 是 02 否
				/*
				 * if("是".equals(row.getCell(10).getStringCellValue())) {
				 * applyServerExtend.setOutShow("01"); }else if
				 * ("否".equals(row.getCell(10).getStringCellValue())) {
				 * applyServerExtend.setOutShow("02"); }
				 */

				try {
					String outShow = DataDictionaryCache.getItemCode("SMP0015", row.getCell(9).getStringCellValue());
					applyServerExtend.setOutShow(outShow);
				} catch (Exception e1) {
					// TODO: handle exception
				}

				// 申请类型 01 新增 02 修改 03 删除
				/*
				 * if("新增".equals(row.getCell(11).getStringCellValue())) {
				 * applyServerExtend.setRequireType("01"); }else if
				 * ("修改".equals(row.getCell(11).getStringCellValue())) {
				 * applyServerExtend.setRequireType("02"); }else if
				 * ("删除".equals(row.getCell(11).getStringCellValue())) {
				 * applyServerExtend.setRequireType("03"); }
				 */
				
				/**
				 * lierhong 20240822
				 */
				String httpMethed = row.getCell(10).getStringCellValue();
				applyServerExtend.setHttpMethed(httpMethed);
				/**
				 * end
				 */
				

				try {
					String requireType = DataDictionaryCache.getItemCode("SMP0013",
							row.getCell(11).getStringCellValue());
					applyServerExtend.setRequireType(requireType);

				} catch (Exception e1) {
					// TODO: handle exception
				}

				try {
					String newTransCode = row.getCell(12).getStringCellValue();
					applyServerExtend.setNewTransCode(newTransCode);

				} catch (Exception e1) {
					// TODO: handle exception
				}

//						applyServerExtend.setRequireType(row.getCell(10).getStringCellValue());

//						applyServerExtend.setFunIntr(row.getCell(12).getStringCellValue());
				// 非空校验
				if (StringUtil.isBlank(applyServerExtend.getRequireType())) {
					response.setCode("0001");
					response.setMessage("第" + (i + 1) + "行数据,[申请类型]无效或为空");
					return response;
				}
				if (StringUtil.isBlank(applyServerExtend.getTransCode())) {
					response.setCode("0001");
					response.setMessage("第" + (i + 1) + "行数据,[交易码]不能为空");
					return response;
				}
				if (StringUtil.isBlank(applyServerExtend.getTransName())) {
					response.setCode("0001");
					response.setMessage("第" + (i + 1) + "行数据,[交易名称]不能为空");
					return response;
				}

				if (StringUtil.isBlank(applyServerExtend.getSystemNo())) {
					response.setCode("0001");
					response.setMessage("第" + (i + 1) + "行数据,[所属系统]不能为空");
					return response;
				} else if (smpSystem == null) {
					response.setCode("0001");
					response.setMessage("第" + (i + 1) + "行数据,[所属系统]不存在");
					return response;
				}

				/*
				 * if (StringUtil.isBlank(applyServerExtend.getMsgAgreement())) {
				 * response.setCode("0001"); response.setMessage("第" + (i + 1) +
				 * "行数据,[报文协议]非法或为空"); return response; }
				 * 
				 * if (StringUtil.isBlank(applyServerExtend.getMsgCode())) {
				 * response.setCode("0001"); response.setMessage("第" + (i + 1) +
				 * "行数据,[报文编码]非法或为空"); return response; }
				 */

				if (StringUtil.isBlank(applyServerExtend.getMsgCode())) {
					response.setCode("0001");
					response.setMessage("第" + (i + 1) + "行数据,[外部可见]非法或为空");
					return response;
				}

				if (StringUtil.isBlank(applyServerExtend.getEsbAddr())) {
					response.setCode("0001");
					response.setMessage("第" + (i + 1) + "行数据,[ESB地址]非法或为空");
					return response;
				} else {
					String esbAddr = applyServerExtend.getEsbAddr();

					EsbEnvironment esbEnvironment = EsbEnvironmentCache.getEsbEnvironment(esbAddr);
					if (esbEnvironment == null) {
						response.setCode("0001");
						response.setMessage("第" + (i + 1) + "行数据,[ESB地址]不存在");
						return response;
					} else {

						if ("01".equals(smpSystem.getSystemType()) && "02".equals(esbEnvironment.getEsbFlg())) {
							response.setCode("0001");
							response.setMessage("第" + (i + 1) + "行数据,[ESB地址]为外联地址，请关联内联ESB地址");
							return response;
						} else if (("02".equals(smpSystem.getSystemType()) || "03".equals(esbEnvironment.getEsbFlg()))
								&& "01".equals(esbEnvironment.getEsbFlg())) {
							response.setCode("0001");
							response.setMessage("第" + (i + 1) + "行数据,[ESB地址]为内联地址，请关联外联ESB地址");
							return response;
						}

						/*
						 * if(!smpSystem.getSystemType().equals(esbEnvironment.getEsbFlg())){
						 * if(smpSystem.getSystemType().equals("01")) { response.setCode("0001");
						 * response.setMessage("第" + (i + 1) + "行数据,[ESB地址]为外联地址，请关联内联ESB地址"); return
						 * response; }else { response.setCode("0001"); response.setMessage("第" + (i + 1)
						 * + "行数据,[ESB地址]为内联地址，请关联外联ESB地址"); return response; } }
						 */
					}
				}

				if (StringUtil.isBlank(applyServerExtend.getTestAddr())) {
					response.setCode("0001");
					response.setMessage("第" + (i + 1) + "行数据,[测试地址]非法或为空");
					return response;
				} else {
					if (("http/json".equals(applyServerExtend.getMsgAgreement())
							|| "http/soap".equals(applyServerExtend.getMsgAgreement()))
							&& !applyServerExtend.getTestAddr().startsWith("http://")) {
						response.setCode("0001");
						response.setMessage("第" + (i + 1) + "行数据,[测试地址]须以http://开头");
						return response;
					} else if ("socket/xml".equals(applyServerExtend.getMsgAgreement())
							&& !applyServerExtend.getTestAddr().startsWith("tcp://")) {
						response.setCode("0001");
						response.setMessage("第" + (i + 1) + "行数据,[测试地址]须以tcp://开头");
						return response;
					}
				}

				// 对ApplyServer进行校验
				// 查询ApplyServer是否有未完成流程
				ApplyServer applyServer = new ApplyServer();
				applyServer.setTransCode(applyServerExtend.getTransCode());
				applyServer.setSystemNo(applyServerExtend.getSystemNo());
				applyServer.setRequireType(applyServerExtend.getRequireType());

				// 调用检验方法
				ResponseMessage<?> check = getServerCheck1(applyServer);
				if ("0001".equals(check.getCode())) {
					response.setCode("0001");
					response.setMessage(check.getMessage());
					return response;
				}

				// 字段表
				// String transCode ="";
				/*
				 * try { transCode = row.getCell(3).getStringCellValue(); }catch (Exception e1)
				 * { // TODO: handle exception }
				 * 
				 * //String systemNo =""; try { systemNo = row.getCell(0).getStringCellValue();
				 * }catch (Exception e1) { // TODO: handle exception }
				 */

				Sheet sheet2 = workbook.getSheet(transCode + "_" + systemNo);

				if (sheet2 == null) {
					response.setCode("0001");
					response.setMessage("未找到系统[" + systemNo + "]的交易[" + transCode + "]详情sheet页，请检查核对");
					return response;
				}

				if (sheet2 != null && sheet2.getPhysicalNumberOfRows() > 0) {

					// 主表applyServer的 功能描述 在第四行 第2列
					applyServerExtend.setFunIntr(sheet2.getRow(3).getCell(1).getStringCellValue());
					// 主表applyServer的 修改说明 在第五行 第2列
					applyServerExtend.setRemark(sheet2.getRow(4).getCell(1).getStringCellValue());

					List<ApplyField> applyFieldList = new ArrayList<>();

					String inout = "01";

					for (int j = 7; j < sheet2.getPhysicalNumberOfRows(); j++) {

						Row row2 = sheet2.getRow(j);// 行从第8行开始

						// 没有值得时候跳出循环
						if (row2 == null || row2.getCell(0) == null) {
							continue;
						}

						try {
							String cell0Value = row2.getCell(0).getStringCellValue();
							if ("".equals(cell0Value)) {
								continue;
							} else if ("响应字段".equals(row2.getCell(0).getStringCellValue())) {
								j++;
								inout = "02";
								continue;
							}
						} catch (Exception e) {
							// 不做处理
						}

						ApplyField applyField = new ApplyField();

						// 序号
						try {

							String orderNumber = row2.getCell(0).getStringCellValue();
							try {
								Integer.parseInt(orderNumber);
							} catch (Exception e) {
								response.setCode("0001");
								response.setMessage(transCode + "|第" + (j + 1) + "行|[序号]不合法,须为数字");
								return response;
							}
							applyField.setOrderNumber(row2.getCell(0).getStringCellValue());
						} catch (Exception e) {
							try {

								applyField.setOrderNumber(
										Integer.toString(new Double(row2.getCell(0).getNumericCellValue()).intValue()));
							} catch (Exception e1) {
								response.setCode("0001");
								response.setMessage(transCode + "|第" + (j + 1) + "行|[序号]不合法,须为数字");
								return response;
							}
						}

						try {
							applyField.setFieldCode(row2.getCell(1).getStringCellValue());
						} catch (Exception e1) {

						}

						try {
							applyField.setFieldName(row2.getCell(2).getStringCellValue());
						} catch (Exception e1) {

						}

						try {
							applyField.setParentType(row2.getCell(3).getStringCellValue());
						} catch (Exception e1) {

						}

						// 节点类型 01 单节点 02 List节点 03 DATAIL节点
						/*
						 * if("单节点".equals(row2.getCell(4).getStringCellValue())) {
						 * applyField.setNodeType("01"); }else if
						 * ("List节点".equals(row2.getCell(4).getStringCellValue())) {
						 * applyField.setNodeType("02"); }else if
						 * ("DATAIL节点".equals(row2.getCell(4).getStringCellValue())) {
						 * applyField.setNodeType("03"); }
						 */
						String nodeType = null;
						try {
							nodeType = DataDictionaryCache.getItemCode("SMP0017", row2.getCell(4).getStringCellValue());
							applyField.setNodeType(nodeType);
						} catch (Exception e1) {

						}

//								applyField.setNodeType(row2.getCell(4).getStringCellValue());

						// 字段类型 01 String 02 Number
						/*
						 * if("String".equals(row2.getCell(5).getStringCellValue())) {
						 * applyField.setFieldType("01"); }else if
						 * ("Number".equals(row2.getCell(5).getStringCellValue())) {
						 * applyField.setFieldType("02"); }
						 */

						try {
							String fieldType = DataDictionaryCache.getItemCode("SMP0018",
									row2.getCell(5).getStringCellValue());
							applyField.setFieldType(fieldType);
						} catch (Exception e1) {

						}

						// 长度
						try {
							applyField.setFieldLength(row2.getCell(6).getStringCellValue());
						} catch (Exception e) {

							if ("01".equals(applyField.getFieldType())) {
								try {
									applyField.setFieldLength(Integer
											.toString(new Double(row2.getCell(6).getNumericCellValue()).intValue()));
								} catch (Exception e1) {
									response.setCode("0001");
									response.setMessage(transCode + "|第" + (j + 1) + "行|[长度]不合法，须为数字");
									return response;
								}
							} else {
								try {
									applyField.setFieldLength(Double.toString(row2.getCell(6).getNumericCellValue()));
								} catch (Exception e1) {

								}
							}
						}

						if ("01".equals(applyField.getFieldType())
								&& (applyField.getFieldLength() == null || "".equals(applyField.getFieldLength()))) {
							response.setCode("0001");
							response.setMessage(transCode + "|第" + (j + 1) + "行|string类型[长度]不能为空");
							return response;
						}

						// 如果是list节点和DETAIL节点，字段类型和字段长度设置为空
						if (!"01".equals(nodeType)) {
							applyField.setFieldType(null);
							applyField.setFieldLength(null);
						}

						// 是否必输 01 是 02 否
						/*
						 * if("是".equals(row2.getCell(7).getStringCellValue())) {
						 * applyField.setFieldRequire("01"); }else if
						 * ("否".equals(row2.getCell(7).getStringCellValue())) {
						 * applyField.setFieldRequire("02"); }
						 */

						try {
							String fieldRequire = DataDictionaryCache.getItemCode("SMP0015",
									row2.getCell(7).getStringCellValue());
							applyField.setFieldRequire(fieldRequire);
						} catch (Exception e1) {

						}

						// 报文结构 01 报文头 02 报文体
						/*
						 * if("报文头".equals(row2.getCell(8).getStringCellValue())) {
						 * applyField.setStruct("01"); }else if
						 * ("报文体".equals(row2.getCell(8).getStringCellValue())) {
						 * applyField.setStruct("02"); }
						 */

						try {
							String struct = DataDictionaryCache.getItemCode("SMP0019",
									row2.getCell(8).getStringCellValue());
							applyField.setStruct(struct);
						} catch (Exception e1) {

						}

						// 输入/输出 01 输入 02 输出
						/*
						 * if("输入".equals(row2.getCell(9).getStringCellValue())) {
						 * applyField.setInOut("01"); }else if
						 * ("输出".equals(row2.getCell(9).getStringCellValue())) {
						 * applyField.setInOut("02"); }
						 */

						// String inOut =DataDictionaryCache.getItemCode("SMP0020",
						// row2.getCell(9).getStringCellValue());

						// applyField.setInOut(inOut);
						applyField.setInOut(inout);

						try {
							applyField.setFieldEdsc(row2.getCell(9).getStringCellValue());
						} catch (Exception e1) {

						}

						// 数据必输项校验

						if (StringUtil.isBlank(applyField.getOrderNumber())) {
							response.setCode("0001");
							response.setMessage(transCode + "|第" + (j + 1) + "行|[序号]不能为空");
							return response;
						}

						if (StringUtil.isBlank(applyField.getFieldCode())) {
							response.setCode("0001");
							response.setMessage(transCode + "|第" + (j + 1) + "行|[字段代码]不能为空");
							return response;
						}
						if (StringUtil.isBlank(applyField.getFieldName())) {
							response.setCode("0001");
							response.setMessage(transCode + "|第" + (j + 1) + "行|[字段名称]不能为空");
							return response;
						}
						if ("01".equals(applyField.getNodeType()) && StringUtil.isBlank(applyField.getFieldType())) {
							response.setCode("0001");
							response.setMessage(transCode + "|第" + (j + 1) + "行|单节点字段[字段类型]不能为空或数据非法");
							return response;
						}
						if (StringUtil.isBlank(applyField.getNodeType())) {
							response.setCode("0001");
							response.setMessage(transCode + "|第" + (j + 1) + "行|[节点类型]不能为空或数据非法");
							return response;
						}
						if (StringUtil.isBlank(applyField.getStruct())) {
							response.setCode("0001");
							response.setMessage(transCode + "|第" + (j + 1) + "行|[报文结构]不能为空或数据非法");
							return response;
						}
						if (StringUtil.isBlank(applyField.getFieldRequire())) {
							response.setCode("0001");
							response.setMessage(transCode + "|第" + (j + 1) + "行|[是否必输]不能为空或数据非法");
							return response;
						}

						applyFieldList.add(applyField);

					}

					applyServerExtend.setApplyFieldList(applyFieldList);
				}

				applyServerExtendList.add(applyServerExtend);
			}

			workbook.close();// 关闭资源

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		response.setExtend(applyServerExtendList);
		logger.info(response.getMessage());
		return response;
	}

	/**
	 * 服务维护校验
	 * 
	 * @param applyServer
	 * @return
	 */
	@RequestMapping("/getServerCheck")
	public ResponseMessage<?> getServerCheck(@RequestBody ApplyServerExtend applyServer) {
		ResponseMessage<?> responseMessage = new ResponseMessage<>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("校验成功！");

		// 查询SmpService 新增表有 或者 修改表无 报错
		SmpService smpService = new SmpService();
		smpService.setTransCode(applyServer.getTransCode());
		smpService.setSystemNo(applyServer.getSystemNo());

		// int SmpServiceInt = smpServiceMapper.selectByCount(smpService);
		SmpService smpService1 = smpServiceMapper.selectByPrimaryKey(smpService);

		if ("01".equals(applyServer.getRequireType()) && smpService1 != null) { // 新增表有
			responseMessage.setCode("0001");
			responseMessage
					.setMessage("系统[" + applyServer.getSystemNo() + "]中服务[" + applyServer.getTransCode() + "]已存在");
			return responseMessage;
		} else if (("02".equals(applyServer.getRequireType()))) { // 修改表无

			if (smpService1 == null) {
				responseMessage.setCode("0001");
				responseMessage
						.setMessage("系统[" + applyServer.getSystemNo() + "]中服务[" + applyServer.getTransCode() + "]不存在");
				return responseMessage;
			}
			/*
			 * else if((!qmsNo.equals(smpService1.getQmsNo()) ||!
			 * batchNum.equals(smpService1.getBatchNum())) &&
			 * "01".equals(smpService1.getStatus())) {//需求编号不一致
			 * responseMessage.setCode("0001");
			 * responseMessage.setMessage("服务"+applyServer.getTransCode()+"存在与"+smpService1.
			 * getQmsNo()+"需求，当前需求不允许修改"); return responseMessage; }
			 */
			else {
				// 查询当前服务关联的服务调用（条件->需求编号不相等|需求状态为未上线）
				/*
				 * List<CallListInfo> callList =
				 * smpSystemCallMapper.getCallListInfo(smpService1); if (callList != null) { for
				 * (CallListInfo callListInfo : callList) { if
				 * ((!applyServer.getQmsNo().equals(callListInfo.getQmsNo()) ||
				 * !applyServer.getBatchNum().equals(callListInfo.getBatchNum())) &&
				 * "01".equals(callListInfo.getStatus())) { responseMessage.setCode("0001");
				 * responseMessage.setMessage("服务" + applyServer.getTransCode() + "在" +
				 * callListInfo.getQmsNo() + "需求中,存在服务调用,当前服务不允许修改"); return responseMessage; }
				 * } }
				 */
			}
		} else if ("03".equals(applyServer.getRequireType())) {
			List<CallListInfo> callList = smpSystemCallMapper.getCallListInfo(smpService1);
			if (callList != null && callList.size() > 0) {
				responseMessage.setCode("0001");
				responseMessage.setMessage("服务" + applyServer.getTransCode() + "存在服务调用,当前服务不允许删除");
				return responseMessage;
			}
		}

		// 查询ApplyServer是否有未完成流程
		int ApplyServerInt = applyServerMapper.selectByCount(applyServer);

		if (ApplyServerInt > 0) {
			responseMessage.setCode("0001");
			responseMessage
					.setMessage("系统[" + applyServer.getSystemNo() + "]中服务[" + applyServer.getTransCode() + "]存在未完成流程");
			return responseMessage;
		}

		return responseMessage;
	}

	public ResponseMessage<?> getServerCheck1(@RequestBody ApplyServer applyServer) {
		ResponseMessage<?> responseMessage = new ResponseMessage<>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("校验成功！");

		// 查询SmpService 新增表有 或者 修改表无 报错
		SmpService smpService = new SmpService();
		smpService.setTransCode(applyServer.getTransCode());
		smpService.setSystemNo(applyServer.getSystemNo());

		int SmpServiceInt = smpServiceMapper.selectByCount(smpService);

		if ("01".equals(applyServer.getRequireType()) && (SmpServiceInt > 0)) { // 新增表有
			responseMessage.setCode("0001");
			responseMessage
					.setMessage("系统[" + applyServer.getSystemNo() + "]中服务[" + applyServer.getTransCode() + "]已存在");
			return responseMessage;
		}

		if (("02".equals(applyServer.getRequireType()) || "03".equals(applyServer.getRequireType()))
				&& (SmpServiceInt == 0)) { // 修改表无
			responseMessage.setCode("0001");
			responseMessage
					.setMessage("系统[" + applyServer.getSystemNo() + "]中服务[" + applyServer.getTransCode() + "]不存在");
			return responseMessage;
		}

		// 查询ApplyServer是否有未完成流程
		int ApplyServerInt = applyServerMapper.selectByCount(applyServer);

		if (ApplyServerInt > 0) {
			responseMessage.setCode("0001");
			responseMessage
					.setMessage("系统[" + applyServer.getSystemNo() + "]中服务[" + applyServer.getTransCode() + "]存在未完成流程");
			return responseMessage;
		}

		return responseMessage;
	}

	/**
	 * 服务调用校验
	 * 
	 * @param applySystemCall
	 * @return
	 */
	@RequestMapping("/getSystemCallCheck")
	public ResponseMessage<?> getSystemCallCheck(@RequestBody ApplySystemCallExtend applySystemCall) {
		ResponseMessage<?> responseMessage = new ResponseMessage<>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("校验成功！");

		// 服务调用是否存在SmpSystemCall
		SmpSystemCallExtend smpSystemCallExtend = new SmpSystemCallExtend();
		smpSystemCallExtend.setBusCode(applySystemCall.getRegCode());
		smpSystemCallExtend.setPubSysCode(applySystemCall.getPubSysCode());
		smpSystemCallExtend.setRegSysCode(applySystemCall.getRegSysCode());

		int a = smpSystemCallMapper.selectByCount(smpSystemCallExtend);

		if ("01".equals(applySystemCall.getRequireType()) && (a > 0)) { // 新增表有
			responseMessage.setCode("0001");
			responseMessage.setMessage("请求系统[" + applySystemCall.getPubSysCode() + "]调用服务系统["
					+ applySystemCall.getRegSysCode() + "]交易[" + applySystemCall.getTransCode() + "]关系已存在");
			return responseMessage;
		}

		if (("02".equals(applySystemCall.getRequireType()) || "03".equals(applySystemCall.getRequireType()))
				&& (a == 0)) { // 修改表无
			responseMessage.setCode("0001");
			responseMessage.setMessage("请求系统[" + applySystemCall.getPubSysCode() + "]调用服务系统["
					+ applySystemCall.getRegSysCode() + "]交易[" + smpSystemCallExtend.getTransCode() + "]关系不存在");

			/* responseMessage.setMessage("修改删除服务调用没有对应数据"); */
			return responseMessage;
		}

		// 查询ApplySystemCall是否有未完成流程
		int applySystemCallInt = applySystemCallMapper.selectByCount(applySystemCall);
		;

		if (applySystemCallInt > 0) {
			responseMessage.setCode("0001");
			responseMessage.setMessage("请求系统[" + applySystemCall.getPubSysCode() + "]调用服务系统["
					+ applySystemCall.getRegSysCode() + "]交易[" + smpSystemCallExtend.getTransCode() + "]存在未完成流程");
			return responseMessage;
		}

		// 如果服务未上线则只能在服务对应的需求里提服务调用
		SmpServiceKey smpServiceKey = new SmpServiceKey();
		smpServiceKey.setSystemNo(applySystemCall.getRegSysCode());
		smpServiceKey.setTransCode(applySystemCall.getTransCode());
		SmpService smpService = smpServiceMapper.selectByPrimaryKey(smpServiceKey);

		if (smpService == null) {
			responseMessage.setCode("0001");
			responseMessage.setMessage(
					"系统[" + applySystemCall.getRegSysCode() + "]交易[" + applySystemCall.getTransCode() + "]不存在");
			return responseMessage;
		} /*
			 * else if( "01".equals(applySystemCall.getRequireType()) &&
			 * "01".equals(smpService.getStatus()) &&
			 * !applySystemCall.getQmsNo().equals(smpService.getQmsNo())) {
			 * responseMessage.setCode("0001");
			 * responseMessage.setMessage(smpService.getTransCode()+"处于未上线状态，请在"+smpService.
			 * getQmsNo()+"需求下申请服务调用,特殊情形请联系开发人员"); return responseMessage; }
			 */

		return responseMessage;
	}

	/**
	 * 服务调用校验
	 * 
	 * @param applySystemCall
	 * @return
	 */
	public ResponseMessage<?> getSystemCallCheck(@RequestBody ApplySystemCall applySystemCall, String qmsNo) {
		ResponseMessage<?> responseMessage = new ResponseMessage<>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("校验成功！");

		// 服务调用是否存在SmpSystemCall
		SmpSystemCallExtend smpSystemCallExtend = new SmpSystemCallExtend();
		smpSystemCallExtend.setBusCode(applySystemCall.getRegCode());
		smpSystemCallExtend.setPubSysCode(applySystemCall.getPubSysCode());
		smpSystemCallExtend.setRegSysCode(applySystemCall.getRegSysCode());

		int a = smpSystemCallMapper.selectByCount(smpSystemCallExtend);

		if ("01".equals(applySystemCall.getRequireType()) && (a > 0)) { // 新增表有
			responseMessage.setCode("0001");
			responseMessage.setMessage("请求系统[" + applySystemCall.getPubSysCode() + "]调用服务系统["
					+ applySystemCall.getRegSysCode() + "]交易[" + applySystemCall.getTransCode() + "]关系已存在");
			return responseMessage;
		}

		if (("02".equals(applySystemCall.getRequireType()) || "03".equals(applySystemCall.getRequireType()))
				&& (a == 0)) { // 修改表无
			responseMessage.setCode("0001");
			responseMessage.setMessage("请求系统[" + applySystemCall.getPubSysCode() + "]调用服务系统["
					+ applySystemCall.getRegSysCode() + "]交易[" + smpSystemCallExtend.getTransCode() + "]关系不存在");
			return responseMessage;
		}

		// 查询ApplySystemCall是否有未完成流程
		int applySystemCallInt = applySystemCallMapper.selectByCount(applySystemCall);
		;

		if (applySystemCallInt > 0) {
			responseMessage.setCode("0001");
			responseMessage.setMessage("请求系统[" + applySystemCall.getPubSysCode() + "]调用服务系统["
					+ applySystemCall.getRegSysCode() + "]交易[" + smpSystemCallExtend.getTransCode() + "]存在未完成流程");
			return responseMessage;
		}

		// 如果服务未上线则只能在服务对应的需求里提服务调用
		SmpServiceKey smpServiceKey = new SmpServiceKey();
		smpServiceKey.setSystemNo(applySystemCall.getRegSysCode());
		smpServiceKey.setTransCode(applySystemCall.getTransCode());
		SmpService smpService = smpServiceMapper.selectByPrimaryKey(smpServiceKey);

		if (smpService == null) {
			responseMessage.setCode("0001");
			responseMessage.setMessage(
					"系统[" + applySystemCall.getRegSysCode() + "]交易[" + applySystemCall.getTransCode() + "]不存在");
			return responseMessage;
		} /*
			 * else if("01".equals(applySystemCall.getRequireType()) &&
			 * "01".equals(smpService.getStatus()) && !qmsNo.equals(smpService.getQmsNo()))
			 * { responseMessage.setCode("0001");
			 * responseMessage.setMessage(smpService.getTransCode()+"处于未上线状态，请在"+smpService.
			 * getQmsNo()+"需求下申请服务调用"); return responseMessage; }
			 */

		return responseMessage;
	}

	/**
	 * 系统维护校验
	 * 
	 * @param applySystem
	 * @return
	 */
	@RequestMapping("/getSystemCheck")
	public ResponseMessage<?> getSystemCheck(@RequestBody ApplySystem applySystem) {
		ResponseMessage<?> responseMessage = new ResponseMessage<>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("校验成功！");

		// 查询SmpSystem 新增表有 或者 修改表无 报错

		SmpSystem smpSystem = new SmpSystem();
		smpSystem.setSystemNo(applySystem.getSystemNo());

		int smpSystemInt = smpServiceManagementSystemMapper.selectByCount(smpSystem);

		if ("01".equals(applySystem.getRequireType()) && (smpSystemInt > 0)) { // 新增表有
			responseMessage.setCode("0001");
			responseMessage.setMessage("系统[" + applySystem.getSystemNo() + "]已存在");
			return responseMessage;
		}

		if (("02".equals(applySystem.getRequireType()) || "03".equals(applySystem.getRequireType()))
				&& (smpSystemInt == 0)) { // 修改表无
			responseMessage.setCode("0001");
			responseMessage.setMessage("系统[" + applySystem.getSystemNo() + "]不存在");
			return responseMessage;
		}

		// 查询ApplySystem是否有未完成流程

		int ApplySystemInt = applySystemMapper.selectByCount(applySystem);

		if (ApplySystemInt > 0) {
			responseMessage.setCode("0001");
			responseMessage.setMessage("系统[" + applySystem.getSystemNo() + "]存在未完成流程");
			return responseMessage;
		}

		return responseMessage;
	}

	/**
	 * 校验登记的环境信息
	 * 
	 * @param applyEnvironment
	 * @return
	 */
	@RequestMapping("/checkEnvirInfo")
	public ResponseMessage<?> checkEnvirInfo(@RequestBody ApplyEnvironment applyEnvironment) {
		ResponseMessage<?> responseMessage = new ResponseMessage();
		responseMessage.setCode("0000");
		responseMessage.setMessage("环境信息校验通过！");

		// 校验工单表是否存在未完成的环境维护工单
		int num = applyEnvironmentMapper.getApplyEnvir(applyEnvironment);
		if (num > 0) {
			responseMessage.setCode("0001");
			responseMessage.setMessage("环境信息校验不通过，存在未完成的环境维护工单！");
		}

		if ("01".equals(applyEnvironment.getRequireType())) {
			SmpEnvironment smpEnvironment = new SmpEnvironment();
			ObjectUtil.copyBeans(applyEnvironment, smpEnvironment);
			int num1 = smpEnvironmentMapper.check(smpEnvironment);
			if (num1 > 0) {
				responseMessage.setCode("0001");
				responseMessage.setMessage("环境信息校验不通过，已存在该条环境信息！");
			}
		}

		logger.info(responseMessage.getMessage());
		return responseMessage;
	}

	@RequestMapping("/generateAll")
	public ResponseMessage<?> generateAll(@RequestParam String applyId) {

		ResponseMessage<?> responseMessage = new ResponseMessage();
		responseMessage.setCode("0000");
		responseMessage.setMessage("配置完成");

		List<ApplyServer> listApplyServer = applyServerMapper.selectNoConfig(applyId);
		String busCode;
		for (ApplyServer applyServer : listApplyServer) {

			if ("01".equals(applyServer.getRequireType())) {
				int id = applyServerMapper.getId();
				if (applyServer.getSystemNo().length() == 9) {
					busCode = "R000" + "10" + String.format("%06d", id);
				} else {
					busCode = "R" + applyServer.getSystemNo() + "10" + String.format("%06d", id);
				}
				applyServer.setBusCode(busCode);
			}

			applyServer.setConfigStatus("02");
			applyServerMapper.updateByPrimaryKey(applyServer);
		}

		logger.info(responseMessage.getMessage());
		return responseMessage;

	}

	/**
	 * 版本比较
	 * @param applyServerKey
	 * @return
	 */
	@RequestMapping("/getBaseBySmpAndApply")
	public ResponseMessage<Map> getBaseBySmpAndApply(@RequestBody ApplyServerKey applyServerKey) {
		ResponseMessage<Map> responseMessage = new ResponseMessage<Map>();

		ApplyServer applyServer = applyServerMapper.selectByPrimaryKey(applyServerKey);

		SmpServiceKey smpServiceKey = new SmpServiceKey();
		smpServiceKey.setTransCode(applyServerKey.getTransCode());
		smpServiceKey.setSystemNo(applyServer.getSystemNo());

		SmpService smpService = smpServiceMapper.selectByPrimaryKey(smpServiceKey);

		Map map2 = new HashMap();

		// 比较基础信息
		if (StringUtil.equals(applyServer.getTransName(), smpService.getTransName())) {
			map2.put("transName", "0");
		} else {
			map2.put("transName", "1");
		}

		if (StringUtil.equals(applyServer.getSystemOrg(), smpService.getSystemOrg())) {
			map2.put("systemOrg", "0");
		} else {
			map2.put("systemOrg", "1");
		}

		if (StringUtil.equals(applyServer.getSystemOrg(), smpService.getSystemOrg())) {
			map2.put("systemOrg", "0");
		} else {
			map2.put("systemOrg", "1");
		}

		if (StringUtil.equals(applyServer.getEsbAddr(), smpService.getEsbAddr())) {
			map2.put("esbAddr", "0");
		} else {
			map2.put("esbAddr", "1");
		}

		if (StringUtil.equals(applyServer.getMsgCode(), smpService.getMsgCode())) {
			map2.put("msgCode", "0");
		} else {
			map2.put("msgCode", "1");
		}

		if (StringUtil.equals(applyServer.getMsgAgreement(), smpService.getMsgAgreement())) {
			map2.put("msgAgreement", "0");
		} else {
			map2.put("msgAgreement", "1");
		}
		if (StringUtil.equals(applyServer.getHttpMethed(), smpService.getHttpMethed())) {
			map2.put("httpMethed", "0");
		} else {
			map2.put("httpMethed", "1");
		}

		if (StringUtil.equals(applyServer.getTestAddr(), smpService.getTestAddr())) {
			map2.put("testAddr", "0");
		} else {
			map2.put("testAddr", "1");
		}

		if (StringUtil.equals(applyServer.getProdAddr(), smpService.getProdAddr())) {
			map2.put("prodAddr", "0");
		} else {
			map2.put("prodAddr", "1");
		}

		if (StringUtil.equals(applyServer.getBusCode(), smpService.getBusCode())) {
			map2.put("busCode", "0");
		} else {
			map2.put("busCode", "1");
		}

		if (StringUtil.equals(applyServer.getBusPath(), smpService.getBusPath())) {
			map2.put("busPath", "0");
		} else {
			map2.put("busPath", "1");
		}

		if (StringUtil.equals(applyServer.getOutShow(), smpService.getOutShow())) {
			map2.put("outShow", "0");
		} else {
			map2.put("outShow", "1");
		}

		if (StringUtil.equals(applyServer.getFunIntr(), smpService.getFunIntr())) {
			map2.put("funIntr", "0");
		} else {
			map2.put("funIntr", "1");
		}

		if (StringUtil.equals(applyServer.getOesbBusPath(), smpService.getOesbBusPath())) {
			map2.put("oesbBusPath", "0");
		} else {
			map2.put("oesbBusPath", "1");
		}

		Map map = new HashMap();
		map.put("applyServer", applyServer);
		map.put("smpService", smpService);
		map.put("baseColor", map2);

		responseMessage.setExtend(map);
		logger.info(responseMessage.getMessage());
		return responseMessage;
	}

	@RequestMapping("/getPathList")
	public ResponseMessage<List<?>> getPathList(@RequestBody SystemCallProxyPath systemCallProxyPath) {
		ResponseMessage<List<?>> responseMessage = new ResponseMessage<List<?>>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("查询成功！");
		PageHelper.startPage(1, 5);
		List<SystemCallProxyPath> systemCallProxyPathList = systemCallProxyPathMapper.getByPage(systemCallProxyPath);

		if (systemCallProxyPathList == null) {
			responseMessage.setCode("0001");
			responseMessage.setMessage("查询失败！");
		}

		List<Map> list = new ArrayList<>();

		for (SystemCallProxyPath systemCallProxyPath1 : systemCallProxyPathList) {
			Map map = new HashMap<>();
			map.put("value", systemCallProxyPath1.getProxyPath());
			list.add(map);
		}

		responseMessage.setExtend(list);
		logger.info(responseMessage.getMessage());
		return responseMessage;
	}
	
	/**
	 * 
	 * @param applyId
	 * @throws IOException
	 */
	@RequestMapping("/exportApplyService")
	public void exportApplyService(@RequestParam String  applyId) throws IOException {
		ResponseMessage<PageInfo<SmpService>> responseMessage = new ResponseMessage<PageInfo<SmpService>>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("查询成功！");
		List<ApplyServerExtend> listSmpService = applyServerMapper.selectByApplyId(applyId);
		response.setContentType("application/octct-stream");
		buildService(response.getOutputStream(), listSmpService);
	}
	
	
	
	
	/**
	 * 导出服务信息
	 * 
	 * @param pageRequest
	 * @return
	 */
	public void buildService(OutputStream out, List<ApplyServerExtend> listSmpService) {
		ResponseMessage<PageInfo<SmpService>> responseMessage = new ResponseMessage<PageInfo<SmpService>>();
		responseMessage.setCode("0000");
		responseMessage.setMessage("查询成功！");

		XSSFWorkbook workbook = new XSSFWorkbook();

		XSSFFont font = workbook.createFont();
		font.setBold(true);
		font.getCTFont().addNewB();

		/**
		 * 加背景
		 */
		XSSFCellStyle cellStyle = workbook.createCellStyle();
		cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
		cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
		cellStyle.setAlignment(HorizontalAlignment.CENTER);

		cellStyle.setBorderBottom(BorderStyle.THIN);
		cellStyle.setBorderTop(BorderStyle.THIN);
		cellStyle.setBorderLeft(BorderStyle.THIN);
		cellStyle.setBorderRight(BorderStyle.THIN);

		/**
		 * 加背景加粗
		 */
		XSSFCellStyle cellStyle3 = workbook.createCellStyle();
		XSSFColor  xssfColor = new XSSFColor(new java.awt.Color(216,228,188));
		cellStyle3.setFillForegroundColor(xssfColor);
		cellStyle3.setFillPattern(FillPatternType.SOLID_FOREGROUND);
		cellStyle3.setAlignment(HorizontalAlignment.CENTER);

		cellStyle3.setBorderBottom(BorderStyle.THIN);
		cellStyle3.setBorderTop(BorderStyle.THIN);
		cellStyle3.setBorderLeft(BorderStyle.THIN);
		cellStyle3.setBorderRight(BorderStyle.THIN);
		cellStyle3.setFont(font);

		/**
		 * 加边框 居中
		 */
		XSSFCellStyle cellStyle1 = workbook.createCellStyle();
		cellStyle1.setAlignment(HorizontalAlignment.CENTER);
		cellStyle1.setBorderBottom(BorderStyle.THIN);
		cellStyle1.setBorderTop(BorderStyle.THIN);
		cellStyle1.setBorderLeft(BorderStyle.THIN);
		cellStyle1.setBorderRight(BorderStyle.THIN);

		/**
		 * 加边框 加粗
		 */
		XSSFCellStyle cellStyle1_1 = workbook.createCellStyle();
		cellStyle1_1.setAlignment(HorizontalAlignment.CENTER);
		cellStyle1_1.setBorderBottom(BorderStyle.THIN);
		cellStyle1_1.setBorderTop(BorderStyle.THIN);
		cellStyle1_1.setBorderLeft(BorderStyle.THIN);
		cellStyle1_1.setBorderRight(BorderStyle.THIN);
		cellStyle1_1.setFont(font);
		
		/**
		 * 加边框 加粗
		 */
		XSSFCellStyle cellStyle1_4 = workbook.createCellStyle();
		cellStyle1_4.setAlignment(HorizontalAlignment.CENTER);
		cellStyle1_4.setFont(font);
		
		/**
		 * 加边框 加粗
		 */
		XSSFCellStyle cellStyle1_2 = workbook.createCellStyle();
		cellStyle1_2.setAlignment(HorizontalAlignment.LEFT);
		cellStyle1_2.setBorderBottom(BorderStyle.THIN);
		cellStyle1_2.setBorderTop(BorderStyle.THIN);
		cellStyle1_2.setBorderLeft(BorderStyle.THIN);
		cellStyle1_2.setBorderRight(BorderStyle.THIN);
		// cellStyle1_2.setFont(font);

		// 获取工作表名称是Index
		Sheet sheet = workbook.createSheet("目录");

		// CellStyle cellStyle = workbook.createCellStyle();

		sheet.setColumnWidth(0, 10 * 256);
		sheet.setColumnWidth(3, 10 * 256);
		sheet.setColumnWidth(4, 40 * 256);
		sheet.setColumnWidth(1, 20 * 256);
		sheet.setColumnWidth(7, 20 * 256);
		sheet.setColumnWidth(8, 40 * 256);
		sheet.setColumnWidth(10, 11 * 256);
		// sheet.setColumnWidth(9, 40*256);
		Row row = sheet.createRow(0);
		Cell cell = row.createCell(0);
		cell.setCellValue("版 本 号：");
		cell.setCellStyle(cellStyle1_4);
		
		cell = row.createCell(1);
		cell.setCellValue(templateversion);
		//cell.setCellStyle(cellStyle1_4);

		 row = sheet.createRow(1);

		String[] title = new String[] { "系统编号", "系统名称", "机构号", "交易码", "交易名称", "报文协议", "报文编码", "ESB测试地址", "测试URL",
				"外部可见","http请求方法", "操作类型", "新交易码" };
		for (int i = 0; i < title.length; i++) {
			 cell = row.createCell(i);
			cell.setCellValue(title[i]);
			cell.setCellStyle(cellStyle3);
		}

		for (int i = 0; i < listSmpService.size(); i++) {
			row = sheet.createRow(i + 2);
			Cell systemNoCell = row.createCell(0);
			systemNoCell.setCellStyle(cellStyle1);
			systemNoCell.setCellValue(listSmpService.get(i).getSystemNo());
			// String systemName =
			// smpSystemMapper.getSystemInfo(listSmpService.get(i).getSystemNo()).getSystemName();
			Cell systemNameCell = row.createCell(1);
			systemNameCell.setCellStyle(cellStyle1);
			systemNameCell.setCellValue(SmpSystemCache.getSystemName(listSmpService.get(i).getSystemNo()));
			Cell systemOrgCell = row.createCell(2);
			systemOrgCell.setCellStyle(cellStyle1);
			systemOrgCell.setCellValue(listSmpService.get(i).getSystemOrg());
			// 交易码
			Cell transCodeCell = row.createCell(3);
			transCodeCell.setCellStyle(cellStyle1);
			transCodeCell.setCellValue(listSmpService.get(i).getTransCode());

			XSSFHyperlink hyperlink = workbook.getCreationHelper().createHyperlink(HyperlinkType.DOCUMENT);
			hyperlink.setAddress(
					listSmpService.get(i).getTransCode() + "_" + listSmpService.get(i).getSystemNo() + "!A1");
			hyperlink.setLabel(listSmpService.get(i).getTransCode());
			transCodeCell.setHyperlink(hyperlink);
			// 交易名称
			Cell transName = row.createCell(4);
			transName.setCellStyle(cellStyle1);
			transName.setCellValue(listSmpService.get(i).getTransName());
			// 报文协议
			Cell msgAgreement = row.createCell(5);
			msgAgreement.setCellStyle(cellStyle1);
			msgAgreement.setCellValue(listSmpService.get(i).getMsgAgreement());
			// 报文编码
			Cell msgCodeCell = row.createCell(6);
			msgCodeCell.setCellStyle(cellStyle1);
			msgCodeCell.setCellValue(DataDictionaryCache.getItemName("SMP0004", listSmpService.get(i).getMsgCode()));
			
			
			// esb地址
			Cell esbAddrCell = row.createCell(7);
			esbAddrCell.setCellStyle(cellStyle1);
			esbAddrCell.setCellValue(listSmpService.get(i).getEsbAddr());

			// 测试地址
			Cell testAddrCell = row.createCell(8);
			testAddrCell.setCellStyle(cellStyle1);
			testAddrCell.setCellValue(listSmpService.get(i).getTestAddr());

			// 生产地址
			/*
			 * Cell prodAddrCell = row.createCell(9); prodAddrCell.setCellStyle(cellStyle1);
			 * prodAddrCell.setCellValue(listSmpService.get(i).getProdAddr());
			 */

			// 外部可见
			Cell outShowCell = row.createCell(9);
			outShowCell.setCellStyle(cellStyle1);
			outShowCell.setCellValue(DataDictionaryCache.getItemName("SMP0015", listSmpService.get(i).getOutShow()));
			//http请求方法
			Cell httpMethed = row.createCell(10);
			httpMethed.setCellStyle(cellStyle1);
			httpMethed.setCellValue( listSmpService.get(i).getHttpMethed());
			
			// 申请类型
			Cell operationShowCell = row.createCell(11);
			operationShowCell.setCellStyle(cellStyle1);
			//operationShowCell.setCellValue("修改");
			operationShowCell.setCellValue(DataDictionaryCache.getItemName("SMP0013", listSmpService.get(i).getRequireType()));


			Cell newTransCodeCell = row.createCell(12);
			newTransCodeCell.setCellStyle(cellStyle1);
			//newTransCodeCell.setCellValue("");
			newTransCodeCell.setCellValue(listSmpService.get(i).getNewTransCode());



			// 字段明细
			XSSFSheet sheetTransCode = workbook
					.createSheet(listSmpService.get(i).getTransCode() + "_" + listSmpService.get(i).getSystemNo());
			CellRangeAddress regin = new CellRangeAddress(1, 1, 1, 9);

			CellRangeAddress regin1 = new CellRangeAddress(2, 2, 1, 9);
			CellRangeAddress regin2 = new CellRangeAddress(3, 3, 1, 9);

			CellRangeAddress regin3 = new CellRangeAddress(4, 4, 1, 9);

//			CellRangeAddress regin4 = new CellRangeAddress(5, 5, 0, 9);

			sheetTransCode.addMergedRegion(regin);
			sheetTransCode.addMergedRegion(regin1);
			sheetTransCode.addMergedRegion(regin2);
			sheetTransCode.addMergedRegion(regin3);
//			sheetTransCode.addMergedRegion(regin4);

			row = sheetTransCode.createRow(0);

			Cell celltitle = row.createCell(0);
			celltitle.setCellValue("返回索引");
			XSSFHyperlink hyperlink1 = workbook.getCreationHelper().createHyperlink(HyperlinkType.DOCUMENT);
			// Hyperlink linetoindex = sheetTransCode.addHyperlink(hyperlink);
			hyperlink1.setAddress("目录!D" + (i + 3));
			hyperlink1.setLabel("返回索引");
			celltitle.setHyperlink(hyperlink1);

			// celltitle.setCellStyle(cellStyle);
			row = sheetTransCode.createRow(1);
			celltitle = row.createCell(0);
			celltitle.setCellStyle(cellStyle1_1);
			celltitle.setCellValue("交易码");
			celltitle = row.createCell(1);
			celltitle.setCellStyle(cellStyle1_2);
			celltitle.setCellValue(listSmpService.get(i).getTransCode());
			for (int j = 2; j < 10; j++) {
				celltitle = row.createCell(j);
				celltitle.setCellStyle(cellStyle1_2);
			}
			row = sheetTransCode.createRow(2);
			celltitle = row.createCell(0);
			celltitle.setCellStyle(cellStyle1_1);
			celltitle.setCellValue("交易名称");
			celltitle = row.createCell(1);
			celltitle.setCellStyle(cellStyle1_2);
			celltitle.setCellValue(listSmpService.get(i).getTransName());
			for (int j = 2; j < 10; j++) {
				celltitle = row.createCell(j);
				celltitle.setCellStyle(cellStyle1_2);
			}

			row = sheetTransCode.createRow(3);
			celltitle = row.createCell(0);
			celltitle.setCellStyle(cellStyle1_1);
			celltitle.setCellValue("功能简介");
			celltitle = row.createCell(1);
			celltitle.setCellStyle(cellStyle1_2);
			celltitle.setCellValue(listSmpService.get(i).getFunIntr());
			for (int j = 2; j < 10; j++) {
				celltitle = row.createCell(j);
				celltitle.setCellStyle(cellStyle1_2);
			}

			row = sheetTransCode.createRow(4);
			celltitle = row.createCell(0);
			celltitle.setCellStyle(cellStyle1_1);
			celltitle.setCellValue("修改说明");
			celltitle = row.createCell(1);
			celltitle.setCellStyle(cellStyle1_2);
			celltitle.setCellValue(listSmpService.get(i).getRemark());
			for (int j = 2; j < 10; j++) {
				celltitle = row.createCell(j);
				celltitle.setCellStyle(cellStyle1_2);
			}

			row = sheetTransCode.createRow(5);
			celltitle = row.createCell(0);
			celltitle.setCellStyle(cellStyle1_2);
			celltitle.setCellValue("请求字段");

			row = sheetTransCode.createRow(6);
			String[] fieldsTitle = { "序号", "字段代码", "字段名称", "父节点", "节点类型", "字段类型", "长度", "是否必输", "报文结构", "描述" };
			XSSFCellStyle cellStyle2 = workbook.createCellStyle();

			cellStyle2.setFillForegroundColor(xssfColor);
			cellStyle2.setFillPattern(FillPatternType.SOLID_FOREGROUND);
			cellStyle2.setAlignment(HorizontalAlignment.CENTER);

			cellStyle2.setBorderBottom(BorderStyle.THIN);
			cellStyle2.setBorderTop(BorderStyle.THIN);
			cellStyle2.setBorderLeft(BorderStyle.THIN);
			cellStyle2.setBorderRight(BorderStyle.THIN);

			for (int j = 0; j < fieldsTitle.length; j++) {
				 cell = row.createCell(j);
				cell.setCellStyle(cellStyle2);
				cell.setCellValue(fieldsTitle[j]);

			}

			// 输入
			ApplyField smpField = new ApplyField();
			smpField.setTransCode(listSmpService.get(i).getTransCode());
			smpField.setSystemNo(listSmpService.get(i).getSystemNo());
			smpField.setInOut("01");
			smpField.setApplyId(listSmpService.get(i).getApplyId());
			List<ApplyField> smpFieldList = applyFieldMapper.getFieldByServer(smpField);
			int insize = smpFieldList.size();
			for (int j = 0; j < smpFieldList.size(); j++) {
				ApplyField field = smpFieldList.get(j);
				row = sheetTransCode.createRow(j + 7);
				Cell orderNumberCell = row.createCell(0);
				orderNumberCell.setCellStyle(cellStyle1);
				orderNumberCell.setCellValue(field.getOrderNumber());
				Cell fieldCodeCell = row.createCell(1);
				fieldCodeCell.setCellStyle(cellStyle1);
				fieldCodeCell.setCellValue(field.getFieldCode());
				Cell fieldNameCell = row.createCell(2);
				fieldNameCell.setCellStyle(cellStyle1);
				fieldNameCell.setCellValue(field.getFieldName());
				Cell parentTypeCell = row.createCell(3);
				parentTypeCell.setCellStyle(cellStyle1);
				parentTypeCell.setCellValue(field.getParentType());
				Cell nodeTypeCell = row.createCell(4);
				nodeTypeCell.setCellStyle(cellStyle1);
				nodeTypeCell.setCellValue(DataDictionaryCache.getItemName("SMP0017", field.getNodeType()));

				Cell fieldTypeCell = row.createCell(5);
				fieldTypeCell.setCellStyle(cellStyle1);

				fieldTypeCell.setCellValue(DataDictionaryCache.getItemName("SMP0018", field.getFieldType()));

				Cell fieldLengthCell = row.createCell(6);
				fieldLengthCell.setCellStyle(cellStyle1);
				fieldLengthCell.setCellValue(field.getFieldLength());
				Cell fieldRequireCell = row.createCell(7);
				fieldRequireCell.setCellStyle(cellStyle1);

				fieldRequireCell.setCellValue(DataDictionaryCache.getItemName("SMP0015", field.getFieldRequire()));

				Cell structCell = row.createCell(8);
				structCell.setCellStyle(cellStyle1);
				structCell.setCellValue(DataDictionaryCache.getItemName("SMP0019", field.getStruct()));

				/*
				 * Cell inOutCell = row.createCell(9); inOutCell.setCellStyle(cellStyle1);
				 * inOutCell.setCellValue(dataDictionaryCache.getItemName("SMP0020",field.
				 * getInOut()));
				 */
				Cell fieldEdsc = row.createCell(9);
				fieldEdsc.setCellStyle(cellStyle1);
				fieldEdsc.setCellValue(field.getFieldEdsc());
			}

			// 输出
			row = sheetTransCode.createRow(insize + 7);
			celltitle = row.createCell(0);
			celltitle.setCellStyle(cellStyle1_2);
			celltitle.setCellValue("响应字段");

			CellRangeAddress regin5 = new CellRangeAddress(insize + 7, insize + 7, 0, 9);

			sheetTransCode.addMergedRegion(regin5);

			row = sheetTransCode.createRow(insize + 8);
			for (int j = 0; j < fieldsTitle.length; j++) {
				 cell = row.createCell(j);
				cell.setCellStyle(cellStyle2);
				cell.setCellValue(fieldsTitle[j]);

			}

			smpField.setTransCode(listSmpService.get(i).getTransCode());
			smpField.setSystemNo(listSmpService.get(i).getSystemNo());
			smpField.setInOut("02");
			smpFieldList = applyFieldMapper.getFieldByServer(smpField);
			for (int j = 0; j < smpFieldList.size(); j++) {
				ApplyField field = smpFieldList.get(j);
				row = sheetTransCode.createRow(j + insize + 9);
				Cell orderNumberCell = row.createCell(0);
				orderNumberCell.setCellStyle(cellStyle1);
				orderNumberCell.setCellValue(field.getOrderNumber());
				Cell fieldCodeCell = row.createCell(1);
				fieldCodeCell.setCellStyle(cellStyle1);
				fieldCodeCell.setCellValue(field.getFieldCode());
				Cell fieldNameCell = row.createCell(2);
				fieldNameCell.setCellStyle(cellStyle1);
				fieldNameCell.setCellValue(field.getFieldName());
				Cell parentTypeCell = row.createCell(3);
				parentTypeCell.setCellStyle(cellStyle1);
				parentTypeCell.setCellValue(field.getParentType());
				Cell nodeTypeCell = row.createCell(4);
				nodeTypeCell.setCellStyle(cellStyle1);

				nodeTypeCell.setCellValue(DataDictionaryCache.getItemName("SMP0017", field.getNodeType()));

				Cell fieldTypeCell = row.createCell(5);
				fieldTypeCell.setCellStyle(cellStyle1);

				fieldTypeCell.setCellValue(DataDictionaryCache.getItemName("SMP0018", field.getFieldType()));

				Cell fieldLengthCell = row.createCell(6);
				fieldLengthCell.setCellStyle(cellStyle1);
				fieldLengthCell.setCellValue(field.getFieldLength());
				Cell fieldRequireCell = row.createCell(7);
				fieldRequireCell.setCellStyle(cellStyle1);

				fieldRequireCell.setCellValue(DataDictionaryCache.getItemName("SMP0015", field.getFieldRequire()));

				Cell structCell = row.createCell(8);
				structCell.setCellStyle(cellStyle1);
				structCell.setCellValue(DataDictionaryCache.getItemName("SMP0019", field.getStruct()));

				/*
				 * Cell inOutCell = row.createCell(9); inOutCell.setCellStyle(cellStyle1);
				 * inOutCell.setCellValue(dataDictionaryCache.getItemName("SMP0020",field.
				 * getInOut()));
				 */
				Cell fieldEdsc = row.createCell(9);
				fieldEdsc.setCellStyle(cellStyle1);
				fieldEdsc.setCellValue(field.getFieldEdsc());
			}

		}

		try {
			workbook.write(out);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				workbook.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

	}
	
	/**
	 * 历史版本比较
	 * @param id 历史版本ID
	 * @return
	 */
	@RequestMapping("/getBaseBySmpAndHis")
	public ResponseMessage<Map> getBaseBySmpAndHis(@RequestParam String  id) {
		ResponseMessage<Map> responseMessage = new ResponseMessage<Map>();

		SmpServiceHis smpServiceHis = smpServiceHisMapper.selectByPrimaryKey(id);

		SmpService smpService = new SmpService();
		smpService.setBusCode(smpServiceHis.getBusCode());
		smpService.setSystemNo(smpServiceHis.getSystemNo());

		smpService = smpServiceMapper.getServiceInfo(smpService);

		Map map2 = new HashMap();

		// 比较基础信息
		if (StringUtil.equals(smpServiceHis.getTransCode(), smpService.getTransCode())) {
			map2.put("transCode", "0");
		} else {
			map2.put("transCode", "1");
		}
		
		if (StringUtil.equals(smpServiceHis.getTransName(), smpService.getTransName())) {
			map2.put("transName", "0");
		} else {
			map2.put("transName", "1");
		}

		if (StringUtil.equals(smpServiceHis.getSystemOrg(), smpService.getSystemOrg())) {
			map2.put("systemOrg", "0");
		} else {
			map2.put("systemOrg", "1");
		}

		if (StringUtil.equals(smpServiceHis.getSystemOrg(), smpService.getSystemOrg())) {
			map2.put("systemOrg", "0");
		} else {
			map2.put("systemOrg", "1");
		}

		if (StringUtil.equals(smpServiceHis.getEsbAddr(), smpService.getEsbAddr())) {
			map2.put("esbAddr", "0");
		} else {
			map2.put("esbAddr", "1");
		}

		if (StringUtil.equals(smpServiceHis.getMsgCode(), smpService.getMsgCode())) {
			map2.put("msgCode", "0");
		} else {
			map2.put("msgCode", "1");
		}

		if (StringUtil.equals(smpServiceHis.getMsgAgreement(), smpService.getMsgAgreement())) {
			map2.put("msgAgreement", "0");
		} else {
			map2.put("msgAgreement", "1");
		}
		
		if (StringUtil.equals(smpServiceHis.getHttpMethed(), smpService.getHttpMethed())) {
			map2.put("httpMethed", "0");
		} else {
			map2.put("httpMethed", "1");
		}

		if (StringUtil.equals(smpServiceHis.getTestAddr(), smpService.getTestAddr())) {
			map2.put("testAddr", "0");
		} else {
			map2.put("testAddr", "1");
		}

		if (StringUtil.equals(smpServiceHis.getProdAddr(), smpService.getProdAddr())) {
			map2.put("prodAddr", "0");
		} else {
			map2.put("prodAddr", "1");
		}

		if (StringUtil.equals(smpServiceHis.getBusCode(), smpService.getBusCode())) {
			map2.put("busCode", "0");
		} else {
			map2.put("busCode", "1");
		}

		if (StringUtil.equals(smpServiceHis.getBusPath(), smpService.getBusPath())) {
			map2.put("busPath", "0");
		} else {
			map2.put("busPath", "1");
		}

		if (StringUtil.equals(smpServiceHis.getOutShow(), smpService.getOutShow())) {
			map2.put("outShow", "0");
		} else {
			map2.put("outShow", "1");
		}

		if (StringUtil.equals(smpServiceHis.getFunIntr(), smpService.getFunIntr())) {
			map2.put("funIntr", "0");
		} else {
			map2.put("funIntr", "1");
		}

		if (StringUtil.equals(smpServiceHis.getOesbBusPath(), smpService.getOesbBusPath())) {
			map2.put("oesbBusPath", "0");
		} else {
			map2.put("oesbBusPath", "1");
		}

		Map map = new HashMap();
		map.put("smpServiceHis", smpServiceHis);
		map.put("smpService", smpService);
		map.put("baseColor", map2);

		responseMessage.setExtend(map);
		logger.info(responseMessage.getMessage());
		return responseMessage;
	}
	
	
	


	
	
	
	

}
